elasticsearch

package
v1.2.40 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ES_DOC_NOT_FOUND = "not found"

	AGG_SUM = "sum"
	AGG_AVG = "avg"
	AGG_MIN = "min"
	AGG_MAX = "max"
	AGG_CNT = "count"
)

Variables

This section is empty.

Functions

func ElasticError

func ElasticError(err error) error

ElasticError is wrapper for errors returned by elasticsearch to provide meaningful error

func NewElasticStore

func NewElasticStore(URI string) (db IDatastore, err error)

NewElasticStore factory method for elasticsearch data store

Types

type ElasticStore

type ElasticStore struct {
	URI string
	// contains filtered or unexported fields
}

func (*ElasticStore) BulkDelete

func (dbs *ElasticStore) BulkDelete(factory EntityFactory, entityIDs []string, keys ...string) (int64, error)

BulkDelete delete multiple entities by IDs

func (*ElasticStore) BulkInsert

func (dbs *ElasticStore) BulkInsert(entities []Entity) (int64, error)

BulkInsert inserts multiple entities

func (*ElasticStore) BulkSetFields

func (dbs *ElasticStore) BulkSetFields(factory EntityFactory, field string, values map[string]any, keys ...string) (int64, error)

BulkSetFields Update specific field of multiple entities in a single transaction (eliminates the need to fetch - change - update) The field is the name of the field, values is a map of entityId -> field value

func (*ElasticStore) BulkUpdate

func (dbs *ElasticStore) BulkUpdate(entities []Entity) (int64, error)

BulkUpdate updates multiple entities

func (*ElasticStore) BulkUpsert

func (dbs *ElasticStore) BulkUpsert(entities []Entity) (int64, error)

BulkUpsert update or insert multiple entities

func (*ElasticStore) CloneDatastore

func (dbs *ElasticStore) CloneDatastore() (IDatastore, error)

CloneDatastore Returns a clone (copy) of the instance

func (*ElasticStore) Close

func (dbs *ElasticStore) Close() error

Close Datastore and free resources

func (*ElasticStore) CreateEntityIndex

func (dbs *ElasticStore) CreateEntityIndex(factory EntityFactory, key string) (string, error)

CreateEntityIndex creates an index of entity and add entity field mapping

func (*ElasticStore) CreateIndex

func (dbs *ElasticStore) CreateIndex(indexName string) (string, error)

CreateIndex creates an index (without mapping)

func (*ElasticStore) Delete

func (dbs *ElasticStore) Delete(factory EntityFactory, entityID string, keys ...string) error

Delete entity by id and shard (key)

func (*ElasticStore) DropIndex

func (dbs *ElasticStore) DropIndex(indexName string) (ack bool, err error)

DropIndex drops an index

func (*ElasticStore) ExecuteQuery added in v1.2.2

func (dbs *ElasticStore) ExecuteQuery(source string, query string, args ...any) ([]Json, error)

ExecuteQuery Execute native KQL query

func (*ElasticStore) Exists

func (dbs *ElasticStore) Exists(factory EntityFactory, entityID string, keys ...string) (bool, error)

Exists checks if entity exists by ID

func (*ElasticStore) Get

func (dbs *ElasticStore) Get(factory EntityFactory, entityID string, keys ...string) (Entity, error)

Get a single entity by ID

func (*ElasticStore) IndexExists

func (dbs *ElasticStore) IndexExists(indexName string) bool

IndexExists tests if index exists

func (*ElasticStore) Insert

func (dbs *ElasticStore) Insert(entity Entity) (Entity, error)

Insert a new entity

func (*ElasticStore) List

func (dbs *ElasticStore) List(factory EntityFactory, entityIDs []string, keys ...string) ([]Entity, error)

List gets multiple entities by IDs

func (*ElasticStore) ListIndices

func (dbs *ElasticStore) ListIndices(pattern string) (map[string]int, error)

ListIndices returns a list of all indices matching the pattern

func (*ElasticStore) Ping

func (dbs *ElasticStore) Ping(retries uint, interval uint) error

Ping tests database connectivity for retries number of time with time interval (in seconds) between retries

func (*ElasticStore) Query

func (dbs *ElasticStore) Query(factory EntityFactory) IQuery

Query is a factory method for query builder Utility

func (*ElasticStore) SetField

func (dbs *ElasticStore) SetField(factory EntityFactory, entityID string, field string, value any, keys ...string) (err error)

SetField update a single field of the document in a single transaction (eliminates the need to fetch - change - update)

func (*ElasticStore) SetFields

func (dbs *ElasticStore) SetFields(factory EntityFactory, entityID string, fields map[string]any, keys ...string) (err error)

SetFields update some fields of the document in a single transaction (eliminates the need to fetch - change - update)

func (*ElasticStore) String

func (dbs *ElasticStore) String() string

String returns the last query DSL

func (*ElasticStore) Update

func (dbs *ElasticStore) Update(entity Entity) (Entity, error)

Update an existing entity only if document exists

func (*ElasticStore) Upsert

func (dbs *ElasticStore) Upsert(entity Entity) (Entity, error)

Upsert update entity or create it if it does not exist

Jump to

Keyboard shortcuts

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