Documentation ¶
Index ¶
- Constants
- func BulkInsert(ctx context.Context, client *elastic.Client, list []string) (*elastic.BulkResponse, error)
- func CreateIndexIfNotExists(ctx context.Context, client *elastic.Client, index, body string) (*elastic.IndicesCreateResult, error)
- func DeleteIndexIfExists(ctx context.Context, client *elastic.Client, index string) (*elastic.IndicesDeleteResponse, error)
- func NewConnection(ops ...Option) (*elastic.Client, error)
- type Decoder
- type Logger
- type Option
- func WithBasicAuth(username, password string) Option
- func WithDecoder(decoder Decoder) Option
- func WithErrorLog(logger Logger) Option
- func WithGzip(enabled bool) Option
- func WithHeaders(headers http.Header) Option
- func WithHealthCheck(enabled bool) Option
- func WithHealthCheckInterval(timeout time.Duration) Option
- func WithHealthCheckTimeout(timeout time.Duration) Option
- func WithHealthCheckTimeoutStartup(timeout time.Duration) Option
- func WithHttpClient(httpClient *http.Client) Option
- func WithInfoLog(logger Logger) Option
- func WithRequiredPlugins(plugins ...string) Option
- func WithRetrier(retrier Retrier) Option
- func WithScheme(scheme string) Option
- func WithSendGetBodyAs(httpMethod string) Option
- func WithSetURL(urls ...string) Option
- func WithSniff(enabled bool) Option
- func WithSnifferCallback(f SnifferCallback) Option
- func WithSnifferInterval(interval time.Duration) Option
- func WithSnifferTimeout(timeout time.Duration) Option
- func WithSnifferTimeoutStartup(timeout time.Duration) Option
- func WithTraceLog(logger Logger) Option
- type Retrier
- type SnifferCallback
Constants ¶
const (
DefaultURL = "http://127.0.0.1:9200"
)
Variables ¶
This section is empty.
Functions ¶
func BulkInsert ¶
func BulkInsert(ctx context.Context, client *elastic.Client, list []string) (*elastic.BulkResponse, error)
BulkInsert execute a new BulkIndexRequest. The operation type is "mappings" by default.
func CreateIndexIfNotExists ¶
func CreateIndexIfNotExists(ctx context.Context, client *elastic.Client, index, body string) (*elastic.IndicesCreateResult, error)
CreateIndexIfNotExists Create elastic mappings if not exists.
func DeleteIndexIfExists ¶
func DeleteIndexIfExists(ctx context.Context, client *elastic.Client, index string) (*elastic.IndicesDeleteResponse, error)
DeleteIndexIfExists delete elastic mappings if exists.
Types ¶
type Decoder ¶
Decoder is used to decode responses from Elasticsearch. Users of elastic can implement their own marshaler for advanced purposes and set them per Client (see WithDecoder). If none is specified, elastic.DefaultDecoder is used.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithBasicAuth ¶
WithBasicAuth can be used to specify the HTTP Basic Auth credentials to use when making HTTP requests to Elasticsearch.
func WithDecoder ¶
WithDecoder sets the Decoder to use when decoding data from Elasticsearch. DefaultDecoder is used by default.
func WithErrorLog ¶
WithErrorLog sets the logger for critical messages like nodes joining or leaving the cluster or failing requests. It is nil by default.
func WithHeaders ¶
WithHeaders adds a list of default HTTP headers that will be added to each requests executed by PerformRequest.
func WithHealthCheck ¶
WithHealthCheck enables or disables healthChecks (enabled by default).
func WithHealthCheckInterval ¶
WithHealthCheckInterval sets the interval between two health checks. The default interval is 60 seconds.
func WithHealthCheckTimeout ¶
WithHealthCheckTimeout sets the timeout for periodic health checks. The default timeout is 1 second (see DefaultHealthCheckTimeout). Notice that a different (usually larger) timeout is used for the initial healthCheck, which is initiated while creating a new client. The startup timeout can be modified with SetHealthCheckTimeoutStartup.
func WithHealthCheckTimeoutStartup ¶
WithHealthCheckTimeoutStartup sets the timeout for the initial health check. The default timeout is 5 seconds (see DefaultHealthCheckTimeoutStartup). Notice that timeouts for subsequent health checks can be modified with SetHealthCheckTimeout.
func WithHttpClient ¶
WithHttpClient can be used to specify the http.Client to use when making HTTP requests to Elasticsearch.
func WithInfoLog ¶
WithInfoLog sets the logger for informational messages, e.g. requests and their response times. It is nil by default.
func WithRequiredPlugins ¶
WithRequiredPlugins can be used to indicate that some plugins are required before a Client will be created.
func WithRetrier ¶
WithRetrier specifies the HTTP method to use when sending a GET request with a body. It is GET by default.
func WithScheme ¶
WithScheme sets the HTTP scheme to look for when sniffing (http or https). This is http by default.
func WithSendGetBodyAs ¶
WithSendGetBodyAs specifies the HTTP method to use when sending a GET request with a body. It is GET by default.
func WithSetURL ¶
WithSetURL defines the URL endpoints of the Elasticsearch nodes. Notice that when sniffing is enabled, these URLs are used to initially sniff the cluster on startup.
func WithSnifferCallback ¶
func WithSnifferCallback(f SnifferCallback) Option
WithSnifferCallback allows the caller to modify sniffer decisions. When setting the callback, the given SnifferCallback is called for each (healthy) node found during the sniffing process. If the callback returns false, the node is ignored: No requests are routed to it.
func WithSnifferInterval ¶
WithSnifferInterval sets the interval between two sniffing processes. The default interval is 15 minutes.
func WithSnifferTimeout ¶
WithSnifferTimeout sets the timeout for the sniffer that finds the nodes in a cluster. The default is 2 seconds. Notice that the timeout used when creating a new client on startup is usually greater and can be set with SetSnifferTimeoutStartup.
func WithSnifferTimeoutStartup ¶
WithSnifferTimeoutStartup sets the timeout for the sniffer that is used when creating a new client. The default is 5 seconds. Notice that the timeout being used for subsequent sniffing processes is set with SetSnifferTimeout.
func WithTraceLog ¶
WithTraceLog specifies the log.Logger to use for output of HTTP requests and responses which is helpful during debugging. It is nil by default.
type SnifferCallback ¶
type SnifferCallback func(*elastic.NodesInfoNode) bool
SnifferCallback defines the protocol for sniffing decisions.