elasticsearch

package
v0.0.0-...-99b9a3e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2017 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ElasticsearchDefaultHost is the default host for elasticsearch.
	ElasticsearchDefaultHost = "localhost"
	// ElasticsearchDefaultPort is the default port for elasticsearch.
	ElasticsearchDefaultPort = "9200"
)

Variables

View Source
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

func GetEsHost

func GetEsHost() string

GetEsHost returns the elasticsearch host.

func GetEsPort

func GetEsPort() string

GetEsPort returns the elasticsearch port.

func RegisterConnectCallback

func RegisterConnectCallback(callback connectCallback)

RegisterConnectCallback registers a callback for the elasticsearch output The callback is called each time the client connects to elasticsearch.

Types

type Backoff

type Backoff struct {
	Init time.Duration
	Max  time.Duration
}

type Client

type Client struct {
	Connection
	// contains filtered or unexported fields
}

Client is an elasticsearch client.

func GetTestingElasticsearch

func GetTestingElasticsearch(t *testing.T) *Client

GetTestingElasticsearch creates a test client.

func NewClient

func NewClient(
	s ClientSettings,
	onConnect *callbacksRegistry,
) (*Client, error)

NewClient instantiates a new client.

func NewConnectedClient

func NewConnectedClient(cfg *common.Config) (*Client, error)

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

func NewElasticsearchClients(cfg *common.Config) ([]Client, error)

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) Clone

func (client *Client) Clone() *Client

Clone clones a client.

func (*Client) GetVersion

func (client *Client) GetVersion() string

GetVersion returns the elasticsearch version the client is connected to

func (*Client) LoadJSON

func (client *Client) LoadJSON(path string, json map[string]interface{}) ([]byte, error)

LoadJSON creates a PUT request based on a JSON document.

func (*Client) Publish

func (client *Client) Publish(batch publisher.Batch) error

func (*Client) Test

func (client *Client) Test(d testing.Driver)

type ClientSettings

type ClientSettings struct {
	URL                string
	Proxy              *url.URL
	TLS                *transport.TLSConfig
	Username, Password string
	Parameters         map[string]string
	Headers            map[string]string
	Index              outil.Selector
	Pipeline           *outil.Selector
	Timeout            time.Duration
	CompressionLevel   int
	Stats              *outputs.Stats
}

ClientSettings contains the settings for a client.

type Connection

type Connection struct {
	URL      string
	Username string
	Password string
	Headers  map[string]string
	// contains filtered or unexported fields
}

Connection manages the connection for a given client.

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

Close closes a connection.

func (*Connection) Connect

func (conn *Connection) Connect() error

Connect connects the client.

func (*Connection) CountSearchURI

func (es *Connection) CountSearchURI(
	index string, docType string,
	params map[string]string,
) (int, *CountResults, error)

CountSearchURI counts the results for a search request.

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)

Ingest pushes a pipeline of updates.

func (*Connection) Ping

func (conn *Connection) Ping() (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) Request

func (conn *Connection) Request(
	method, path string,
	pipeline string,
	params map[string]string,
	body interface{},
) (int, []byte, error)

Request sends a request via the connection.

func (*Connection) RequestURL

func (conn *Connection) RequestURL(
	method, url string,
	body interface{},
) (int, []byte, error)

RequestURL sends a request with the connection object to an alternative url

func (*Connection) SearchURI

func (es *Connection) SearchURI(index string, docType string, params map[string]string) (int, *SearchResults, error)

SearchURI executes a search request 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"`
}

CountResults contains the count of results.

type Hits

type Hits struct {
	Total int
	Hits  []json.RawMessage `json:"hits"`
}

Hits contains the 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"`
	Exists       bool            `json:"exists"`
	Found        bool            `json:"found"`   // Only used prior to ES 6. You must also check for Result == "found".
	Created      bool            `json:"created"` // Only used prior to ES 6. You must also check for Result == "created".
	Result       string          `json:"result"`  // Only used in ES 6+.
	Acknowledged bool            `json:"acknowledged"`
	Matches      []string        `json:"matches"`
}

QueryResult contains the result of a query.

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"`
}

SearchResults contains the results of a search.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL