Documentation ¶
Overview ¶
Package elasticsearch implements the Elasticsearch storage.
Index ¶
- Constants
- func Get() storage.IStorage
- func Set(s storage.IStorage)
- func ToElasticSearchString(s customsort.Sort) (string, error)
- type Config
- type CountResponse
- type DynamicIndexFunc
- type ElasticSearch
- func (es *ElasticSearch) Count(ctx context.Context, target string, prm *count.Count, ...) (int64, error)
- func (es *ElasticSearch) Create(ctx context.Context, id, target string, v any, prm *create.Create, ...) (string, error)
- func (es *ElasticSearch) CreateIndex(ctx context.Context, name, mapping string) error
- func (es *ElasticSearch) Delete(ctx context.Context, id, target string, prm *delete.Delete, ...) error
- func (es *ElasticSearch) DeleteIndex(ctx context.Context, name string) error
- func (es *ElasticSearch) GetClient() any
- func (es *ElasticSearch) List(ctx context.Context, target string, v any, prm *list.List, ...) error
- func (es *ElasticSearch) Retrieve(ctx context.Context, id, target string, v any, prm *retrieve.Retrieve, ...) error
- func (es *ElasticSearch) Update(ctx context.Context, id, target string, v any, prm *update.Update, ...) error
- type ResponseError
- type ResponseErrorFromES
- type ResponseErrorFromESReason
- type ResponseSourceFromES
Constants ¶
const Name = "elasticsearch"
Name of the storage.
Variables ¶
This section is empty.
Functions ¶
func ToElasticSearchString ¶
func ToElasticSearchString(s customsort.Sort) (string, error)
ToElasticSearchString converts the `Sort` to ElasticSearch sort format.
Types ¶
type CountResponse ¶
type CountResponse struct { Took int `json:"took"` TimedOut bool `json:"timed_out"` Shards struct { Total int `json:"total"` Successful int `json:"successful"` Skipped int `json:"skipped"` Failed int `json:"failed"` } `json:"_shards"` Hits struct { Total struct { Value int `json:"value"` Relation string `json:"relation"` } `json:"total"` MaxScore any `json:"max_score"` Hits []any `json:"hits"` } `json:"hits"` }
CountResponse is the response from the Count operation.
type DynamicIndexFunc ¶
type DynamicIndexFunc func() string
DynamicIndexFunc is a function which defines the name of the index, and evaluated at the index time.
type ElasticSearch ¶
type ElasticSearch struct { *storage.Storage // Client is the ElasticSearch client. Client *elasticsearch.Client `json:"-" validate:"required"` // Config is the ElasticSearch configuration. Config Config `json:"-"` // Target allows to set a static target. If it is empty, the target will be // dynamic - the one set at the operation (count, create, delete, etc) time. // Depending on the storage, target is a collection, a table, a bucket, etc. // For ElasticSearch, for example it doesn't have a concept of a database - // the target then is the index. Due to different cases of ElasticSearch // usage, the target can be static or dynamic - defined at the index time, // for example: log-{YYYY}-{MM}. For Redis, it isn't used at all. Target DynamicIndexFunc `json:"-"` }
ElasticSearch storage definition.
func New ¶
func New(ctx context.Context, cfg Config) (*ElasticSearch, error)
New returns a new `ElasticSearch` storage.
func NewWithDynamicIndex ¶
func NewWithDynamicIndex( ctx context.Context, dynamicIndexFunc DynamicIndexFunc, cfg Config, ) (*ElasticSearch, error)
NewWithDynamicIndex returns a new `ElasticSearch` storage. It allows to define a function which defines the name of the index, and evaluated at the index time.
func NewWithIndex ¶
NewWithIndex returns a new `ElasticSearch` storage specifying the index name.
func (*ElasticSearch) Count ¶
func (es *ElasticSearch) Count(ctx context.Context, target string, prm *count.Count, options ...storage.Func[*count.Count]) (int64, error)
Count returns the number of items in the storage.
func (*ElasticSearch) Create ¶ added in v0.0.15
func (es *ElasticSearch) Create(ctx context.Context, id, target string, v any, prm *create.Create, options ...storage.Func[*create.Create]) (string, error)
Create data.
NOTE: Not all storages returns the ID, neither all storages requires `id` to be set. You are better off setting the ID yourself.
func (*ElasticSearch) CreateIndex ¶
func (es *ElasticSearch) CreateIndex(ctx context.Context, name, mapping string) error
CreateIndex creates a new index in Elasticsearch.
func (*ElasticSearch) Delete ¶
func (es *ElasticSearch) Delete(ctx context.Context, id, target string, prm *delete.Delete, options ...storage.Func[*delete.Delete]) error
Delete removes data.
func (*ElasticSearch) DeleteIndex ¶
func (es *ElasticSearch) DeleteIndex(ctx context.Context, name string) error
DeleteIndex deletes a new index in Elasticsearch.
func (*ElasticSearch) GetClient ¶
func (es *ElasticSearch) GetClient() any
GetClient returns the client.
func (*ElasticSearch) List ¶
func (es *ElasticSearch) List(ctx context.Context, target string, v any, prm *list.List, options ...storage.Func[*list.List]) error
List data.
NOTE: It uses param.List.Search to query the data.
type ResponseError ¶
ResponseError is the error from the Elasticsearch response.
type ResponseErrorFromES ¶
type ResponseErrorFromES struct { Error ResponseErrorFromESReason `json:"error"` Status int `json:"status"` }
ResponseErrorFromES is the error from the Elasticsearch response.
type ResponseErrorFromESReason ¶
type ResponseErrorFromESReason struct {
Reason string `json:"reason"`
}
ResponseErrorFromESReason is the reason from the Elasticsearch response.
type ResponseSourceFromES ¶
type ResponseSourceFromES struct {
Data interface{} `json:"_source"`
}
ResponseSourceFromES is the data from the Elasticsearch response.