Documentation ¶
Index ¶
- Constants
- Variables
- func GetEsHost() string
- func GetEsPort() string
- func New(beatName string, cfg *common.Config, topologyExpire int) (outputs.Outputer, error)
- type Client
- func (client *Client) CheckTemplate(templateName string) bool
- func (client *Client) Clone() *Client
- func (client *Client) GetVersion() string
- func (client *Client) LoadJSON(path string, json map[string]interface{}) ([]byte, error)
- func (client *Client) LoadTemplate(templateName string, template map[string]interface{}) error
- func (client *Client) PublishEvent(data outputs.Data) error
- func (client *Client) PublishEvents(data []outputs.Data) ([]outputs.Data, error)
- type ClientSettings
- type Connection
- func (conn *Connection) Bulk(index, docType string, params map[string]string, body []interface{}) (*QueryResult, error)
- func (conn *Connection) BulkWith(index string, docType string, params map[string]string, ...) (*QueryResult, error)
- func (conn *Connection) Close() error
- func (conn *Connection) Connect(timeout time.Duration) error
- func (es *Connection) CountSearchURI(index string, docType string, params map[string]string) (int, *CountResults, error)
- func (es *Connection) CreateIndex(index string, body interface{}) (int, *QueryResult, error)
- func (es *Connection) CreatePipeline(id string, params map[string]string, body interface{}) (int, *QueryResult, error)
- func (es *Connection) Delete(index string, docType string, id string, params map[string]string) (int, *QueryResult, error)
- func (es *Connection) DeletePipeline(id string, params map[string]string) (int, *QueryResult, error)
- func (conn *Connection) GetVersion() string
- func (es *Connection) Index(index, docType, id string, params map[string]string, body interface{}) (int, *QueryResult, error)
- func (es *Connection) IndexExists(index string) (int, error)
- func (es *Connection) Ingest(index, docType, pipeline, id string, params map[string]string, ...) (int, *QueryResult, error)
- func (conn *Connection) Ping(timeout time.Duration) (string, error)
- func (es *Connection) Refresh(index string) (int, *QueryResult, error)
- func (conn *Connection) Request(method, path string, pipeline string, params map[string]string, ...) (int, []byte, error)
- func (es *Connection) SearchURI(index string, docType string, params map[string]string) (int, *SearchResults, error)
- type CountResults
- type Hits
- type MetaBuilder
- type QueryResult
- type SearchResults
- type Template
- type TemplateVersion
- type TemplateVersions
Constants ¶
const ElasticsearchDefaultHost = "localhost"
const ElasticsearchDefaultPort = "9200"
Variables ¶
var ( // ErrNotConnected indicates failure due to client having no valid connection ErrNotConnected = errors.New("not connected") // ErrJSONEncodeFailed indicates encoding failures ErrJSONEncodeFailed = errors.New("json encode failed") // ErrResponseRead indicates error parsing Elasticsearch response ErrResponseRead = errors.New("bulk item status parse failed") )
Functions ¶
Types ¶
type Client ¶
type Client struct { Connection // contains filtered or unexported fields }
func GetTestingElasticsearch ¶
func GetTestingElasticsearch() *Client
func NewClient ¶
func NewClient( s ClientSettings, onConnectCallback connectCallback, ) (*Client, error)
NewClient instantiates a new client.
func NewConnectedClient ¶
NewConnectedClient creates a new Elasticsearch client based on the given config. It uses the NewElasticsearchClients to create a list of clients then returns the first from the list that successfully connects.
func NewElasticsearchClients ¶
NewElasticsearchClients returns a list of Elasticsearch clients based on the given configuration. It accepts the same configuration parameters as the output, except for the output specific configuration options (index, pipeline, template) .If multiple hosts are defined in the configuration, a client is returned for each of them.
func (*Client) CheckTemplate ¶ added in v1.2.0
CheckTemplate checks if a given template already exist. It returns true if and only if Elasticsearch returns with HTTP status code 200.
func (*Client) GetVersion ¶
GetVersion returns the elasticsearch version the client is connected to
func (*Client) LoadTemplate ¶ added in v1.2.0
LoadTemplate loads a template into Elasticsearch overwriting the existing template if it exists. If you wish to not overwrite an existing template then use CheckTemplate prior to calling this method.
func (*Client) PublishEvents ¶
PublishEvents sends all events to elasticsearch. On error a slice with all events not published or confirmed to be processed by elasticsearch will be returned. The input slice backing memory will be reused by return the value.
type ClientSettings ¶
type Connection ¶
type Connection struct { URL string Username string Password string Headers map[string]string // contains filtered or unexported fields }
func (*Connection) Bulk ¶
func (conn *Connection) Bulk( index, docType string, params map[string]string, body []interface{}, ) (*QueryResult, error)
Bulk performs many index/delete operations in a single API call. Implements: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
func (*Connection) BulkWith ¶
func (conn *Connection) BulkWith( index string, docType string, params map[string]string, metaBuilder MetaBuilder, body []interface{}, ) (*QueryResult, error)
BulkWith creates a HTTP request containing a bunch of operations and send them to Elasticsearch. The request is retransmitted up to max_retries before returning an error.
func (*Connection) Close ¶
func (conn *Connection) Close() error
func (*Connection) CountSearchURI ¶
func (es *Connection) CountSearchURI( index string, docType string, params map[string]string, ) (int, *CountResults, error)
func (*Connection) CreateIndex ¶
func (es *Connection) CreateIndex(index string, body interface{}) (int, *QueryResult, error)
CreateIndex creates a new index, optionally with settings and mappings passed in the body. Implements: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
func (*Connection) CreatePipeline ¶
func (es *Connection) CreatePipeline( id string, params map[string]string, body interface{}, ) (int, *QueryResult, error)
CreatePipeline create a new ingest pipeline with name id. Implements: https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html
func (*Connection) Delete ¶
func (es *Connection) Delete(index string, docType string, id string, params map[string]string) (int, *QueryResult, error)
Delete deletes a typed JSON document from a specific index based on its id. Implements: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
func (*Connection) DeletePipeline ¶
func (es *Connection) DeletePipeline( id string, params map[string]string, ) (int, *QueryResult, error)
DeletePipeline deletes an ingest pipeline by id. Implements: https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html
func (*Connection) GetVersion ¶
func (conn *Connection) GetVersion() string
func (*Connection) Index ¶
func (es *Connection) Index( index, docType, id string, params map[string]string, body interface{}, ) (int, *QueryResult, error)
Index adds or updates a typed JSON document in a specified index, making it searchable. In case id is empty, a new id is created over a HTTP POST request. Otherwise, a HTTP PUT request is issued. Implements: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
func (*Connection) IndexExists ¶
func (es *Connection) IndexExists(index string) (int, error)
IndexExists checks if an index exists. Implements: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html
func (*Connection) Ingest ¶
func (es *Connection) Ingest( index, docType, pipeline, id string, params map[string]string, body interface{}, ) (int, *QueryResult, error)
func (*Connection) Ping ¶
func (conn *Connection) Ping(timeout time.Duration) (string, error)
Ping sends a GET request to the Elasticsearch
func (*Connection) Refresh ¶
func (es *Connection) Refresh(index string) (int, *QueryResult, error)
Refresh an index. Call this after doing inserts or creating/deleting indexes in unit tests.
func (*Connection) SearchURI ¶
func (es *Connection) SearchURI(index string, docType string, params map[string]string) (int, *SearchResults, error)
A search request can be executed purely using a URI by providing request parameters. Implements: http://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html
type CountResults ¶
type CountResults struct { Count int `json:"count"` Shards json.RawMessage `json:"_shards"` }
type Hits ¶
type Hits struct { Total int Hits []json.RawMessage `json:"hits"` }
type MetaBuilder ¶
type MetaBuilder func(interface{}) interface{}
MetaBuilder creates meta data for bulk requests
type QueryResult ¶
type QueryResult struct { Ok bool `json:"ok"` Index string `json:"_index"` Type string `json:"_type"` ID string `json:"_id"` Source json.RawMessage `json:"_source"` Version int `json:"_version"` Found bool `json:"found"` Exists bool `json:"exists"` Created bool `json:"created"` Acknowledged bool `json:"acknowledged"` Matches []string `json:"matches"` }
func (QueryResult) String ¶
func (r QueryResult) String() string
type SearchResults ¶
type SearchResults struct { Took int `json:"took"` Shards json.RawMessage `json:"_shards"` Hits Hits `json:"hits"` Aggs map[string]json.RawMessage `json:"aggregations"` }
type Template ¶
type Template struct { Enabled bool `config:"enabled"` Name string `config:"name"` Path string `config:"path"` Overwrite bool `config:"overwrite"` Versions TemplateVersions `config:"versions"` }
type TemplateVersion ¶
type TemplateVersions ¶
type TemplateVersions struct { Es2x TemplateVersion `config:"2x"` Es6x TemplateVersion `config:"6x"` }