Documentation ¶
Index ¶
- func Connect(ctx context.Context, elasticsearchURL string, options ...connectOption) (*elasticsearch.Client, error)
- func ErrorReason(err error) string
- func IsConflict(err interface{}) bool
- func IsContextErr(err error) bool
- func IsForbidden(err interface{}) bool
- func IsNotFound(err interface{}) bool
- func IsStatusCode(err interface{}, code int) bool
- func IsTimeout(err interface{}) bool
- func IsUnauthorized(err interface{}) bool
- func ParseError(res *esapi.Response, err error) error
- func ParseHTTPResponse(res *http.Response, err error) error
- func Ping(ctx context.Context, es *elasticsearch.Client) error
- func WithDebug(debug bool) connectOption
- func WithPassword(password string) connectOption
- func WithPostStart(funcs ...postStartFunc) startConfigFunc
- func WithTimeout(timeout time.Duration) startConfigFunc
- func WithUsername(username string) connectOption
- type Container
- type ContainerCache
- type Error
- type ErrorDetails
- type ScriptErrorPosition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
func Connect(ctx context.Context, elasticsearchURL string, options ...connectOption) (*elasticsearch.Client, error)
Connect to Elasticsearch.
func ErrorReason ¶
ErrorReason returns the reason of an error that Elasticsearch reported, if err is of kind Error and has ErrorDetails with a Reason. Any other value of err will return an empty string.
func IsConflict ¶
func IsConflict(err interface{}) bool
IsConflict returns true if the given error indicates that the Elasticsearch operation resulted in a version conflict. This can occur in operations like `update` or `index` with `op_type=create`. The err parameter can be of type *elastic.Error, elastic.Error, *http.Response or int (indicating the HTTP status code).
func IsContextErr ¶
IsContextErr returns true if the error is from a context that was canceled or deadline exceeded
func IsForbidden ¶
func IsForbidden(err interface{}) bool
IsForbidden returns true if the given error indicates that Elasticsearch returned HTTP status 403. This happens e.g. due to a missing license. The err parameter can be of type *elastic.Error, elastic.Error, *http.Response or int (indicating the HTTP status code).
func IsNotFound ¶
func IsNotFound(err interface{}) bool
IsNotFound returns true if the given error indicates that Elasticsearch returned HTTP status 404. The err parameter can be of type *elastic.Error, elastic.Error, *http.Response or int (indicating the HTTP status code).
func IsStatusCode ¶
IsStatusCode returns true if the given error indicates that the Elasticsearch operation returned the specified HTTP status code. The err parameter can be of type *http.Response, *Error, Error, or int (indicating the HTTP status code).
func IsTimeout ¶
func IsTimeout(err interface{}) bool
IsTimeout returns true if the given error indicates that Elasticsearch returned HTTP status 408. The err parameter can be of type *elastic.Error, elastic.Error, *http.Response or int (indicating the HTTP status code).
func IsUnauthorized ¶
func IsUnauthorized(err interface{}) bool
IsUnauthorized returns true if the given error indicates that Elasticsearch returned HTTP status 401. This happens e.g. when the cluster is configured to require HTTP Basic Auth. The err parameter can be of type *elastic.Error, elastic.Error, *http.Response or int (indicating the HTTP status code).
func ParseError ¶
ParseError will parse the response and return a decoded Error returned by Elasticsearch.
1. If err is not nil, return err. 2. If res is nil, return nil. 3. If res is not an error, return nil. 4. If res cannot be decoded into an ES error, return the decoding error. 4. Return an *Error instance.
func ParseHTTPResponse ¶
ParseHTTPResponse is like ParseError but expects a raw http.Response.
func WithDebug ¶
func WithDebug(debug bool) connectOption
WithDebug sets the debug mode for the elasticsearch connection.
func WithPassword ¶
func WithPassword(password string) connectOption
WithPassword sets the password for the elasticsearch connection.
func WithPostStart ¶
func WithPostStart(funcs ...postStartFunc) startConfigFunc
WithPostStart adds a post-startup operation to the container. This can be used to install extensions, create tables, seed data etc.
func WithTimeout ¶
func WithUsername ¶
func WithUsername(username string) connectOption
WithUsername sets the username for the elasticsearch connection.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
type ContainerCache ¶
type ContainerCache struct {
// contains filtered or unexported fields
}
ContainerCache is a thread-safe cache for elasticsearch containers.
func NewContainerCache ¶
func NewContainerCache() *ContainerCache
NewContainerCache returns a new ContainerCache.
func (*ContainerCache) Close ¶
func (p *ContainerCache) Close() error
Close stops all containers in the cache.
func (*ContainerCache) GetOrCreate ¶
func (p *ContainerCache) GetOrCreate(id string, createFunc func() *Container) *Container
GetOrCreate starts a new container if none is running, otherwise returns the pooled container.
type Error ¶
type Error struct { Status int `json:"status"` Details *ErrorDetails `json:"error,omitempty"` }
Error encapsulates error details as returned from Elasticsearch.
type ErrorDetails ¶
type ErrorDetails struct { Type string `json:"type"` Reason string `json:"reason"` ResourceType string `json:"resource.type,omitempty"` ResourceId string `json:"resource.id,omitempty"` Index string `json:"index,omitempty"` Phase string `json:"phase,omitempty"` Grouped bool `json:"grouped,omitempty"` CausedBy map[string]interface{} `json:"caused_by,omitempty"` RootCause []*ErrorDetails `json:"root_cause,omitempty"` FailedShards []map[string]interface{} `json:"failed_shards,omitempty"` ScriptStack []string `json:"script_stack,omitempty"` // from ScriptException Script string `json:"script,omitempty"` // from ScriptException Lang string `json:"lang,omitempty"` // from ScriptException Position *ScriptErrorPosition `json:"position,omitempty"` // from ScriptException (7.7+) }
ErrorDetails encapsulate error details from Elasticsearch. It is used in e.g. elastic.Error and elastic.BulkResponseItem.
type ScriptErrorPosition ¶
type ScriptErrorPosition struct { Offset int `json:"offset"` Start int `json:"start"` End int `json:"end"` }
ScriptErrorPosition specifies the position of the error in a script. It is used in ErrorDetails for scripting errors.