elasticsearch

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

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

func NewConnection

func NewConnection(ops ...Option) (*elastic.Client, error)

NewConnection initialize elastic client instance for connection.

Types

type Decoder

type Decoder = elastic.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 Logger

type Logger = elastic.Logger

Logger specifies the interface for all log operations.

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithBasicAuth

func WithBasicAuth(username, password string) Option

WithBasicAuth can be used to specify the HTTP Basic Auth credentials to use when making HTTP requests to Elasticsearch.

func WithDecoder

func WithDecoder(decoder Decoder) Option

WithDecoder sets the Decoder to use when decoding data from Elasticsearch. DefaultDecoder is used by default.

func WithErrorLog

func WithErrorLog(logger Logger) Option

WithErrorLog sets the logger for critical messages like nodes joining or leaving the cluster or failing requests. It is nil by default.

func WithGzip

func WithGzip(enabled bool) Option

WithGzip enables or disables gzip compression (disabled by default).

func WithHeaders

func WithHeaders(headers http.Header) Option

WithHeaders adds a list of default HTTP headers that will be added to each requests executed by PerformRequest.

func WithHealthCheck

func WithHealthCheck(enabled bool) Option

WithHealthCheck enables or disables healthChecks (enabled by default).

func WithHealthCheckInterval

func WithHealthCheckInterval(timeout time.Duration) Option

WithHealthCheckInterval sets the interval between two health checks. The default interval is 60 seconds.

func WithHealthCheckTimeout

func WithHealthCheckTimeout(timeout time.Duration) Option

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

func WithHealthCheckTimeoutStartup(timeout time.Duration) Option

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

func WithHttpClient(httpClient *http.Client) Option

WithHttpClient can be used to specify the http.Client to use when making HTTP requests to Elasticsearch.

func WithInfoLog

func WithInfoLog(logger Logger) Option

WithInfoLog sets the logger for informational messages, e.g. requests and their response times. It is nil by default.

func WithRequiredPlugins

func WithRequiredPlugins(plugins ...string) Option

WithRequiredPlugins can be used to indicate that some plugins are required before a Client will be created.

func WithRetrier

func WithRetrier(retrier Retrier) Option

WithRetrier specifies the HTTP method to use when sending a GET request with a body. It is GET by default.

func WithScheme

func WithScheme(scheme string) Option

WithScheme sets the HTTP scheme to look for when sniffing (http or https). This is http by default.

func WithSendGetBodyAs

func WithSendGetBodyAs(httpMethod string) Option

WithSendGetBodyAs specifies the HTTP method to use when sending a GET request with a body. It is GET by default.

func WithSetURL

func WithSetURL(urls ...string) Option

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 WithSniff

func WithSniff(enabled bool) Option

WithSniff enables or disables the sniffer (enabled by default).

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

func WithSnifferInterval(interval time.Duration) Option

WithSnifferInterval sets the interval between two sniffing processes. The default interval is 15 minutes.

func WithSnifferTimeout

func WithSnifferTimeout(timeout time.Duration) Option

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

func WithSnifferTimeoutStartup(timeout time.Duration) Option

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

func WithTraceLog(logger Logger) Option

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 Retrier

type Retrier = elastic.Retrier

Retrier decides whether to retry a failed HTTP request with Elasticsearch.

type SnifferCallback

type SnifferCallback func(*elastic.NodesInfoNode) bool

SnifferCallback defines the protocol for sniffing decisions.

Jump to

Keyboard shortcuts

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