elasticx

package
v0.0.104 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const IndexNotFoundExceptionName = "index_not_found_exception"

Variables

View Source
var DefaultDocumentOptions = &documentOptions{
	refresh:           refresh.False,
	waitForCompletion: false,
}

Functions

This section is empty.

Types

type Client

type Client interface {
	// Init makes sure that the elastic server or cluster is configured for clinia
	Init(ctx context.Context) error

	// Clean makes sure the the elastic server or cluster removes all clinia configuration
	Clean(ctx context.Context) error

	ClientEngines
}

Client provides access to a single Elastic server, or an entire cluster of Elastic servers.

func NewClient

func NewClient(config elasticsearch.Config) (Client, error)

NewClient creates a new Client based on the given config.

type ClientEngines

type ClientEngines interface {
	// Engine opens a connection to an exisiting engine.
	// If no engine with given name exists, a NotFoundError is returned.
	Engine(ctx context.Context, name string) (Engine, error)

	// EngineExists returns true if an engine with given name exists.
	EngineExists(ctx context.Context, name string) (bool, error)

	// Engines returns a list of all engines found by the client.
	Engines(ctx context.Context) ([]EngineInfo, error)

	// CreateEngine creates a new engine with given name and opens a connection to it.
	// If the a database with given name already exists, a DuplicateError is returned.
	CreateEngine(ctx context.Context, name string) (Engine, error)
}

ClientEngines provides access to the engines in a single elastic server, or an entire cluster of elastic servers.

type CreateIndexOptions

type CreateIndexOptions struct {
	Aliases  map[string]types.Alias
	Settings *types.IndexSettings
	Mappings *types.TypeMapping
}

CreateIndexOptions contains options that customize the creation of an index.

type DeleteQueryResponse added in v0.0.71

type DeleteQueryResponse struct {
	TaskId      *TaskId
	DeleteCount int64
}

type DocumentMeta

type DocumentMeta struct {
	ID      string `json:"_id"`
	Index   string `json:"_index"`
	Version int64  `json:"_version"`
}

type DocumentOption added in v0.0.27

type DocumentOption func(*documentOptions)

func WithRefresh added in v0.0.27

func WithRefresh(refresh refresh.Refresh) DocumentOption

WithRefresh sets the refresh option of the document operation.

func WithWaitForCompletion added in v0.0.71

func WithWaitForCompletion(waitForCompletion bool) DocumentOption

type Engine

type Engine interface {
	// Name returns the name of the engine.
	Name() string

	// Info fetches the information about the engine.
	Info(ctx context.Context) (*EngineInfo, error)

	// Remove removes the entire engine.
	// If the engine does not exists, a NotFoundError us returned
	Remove(ctx context.Context) error

	// Index functions
	EngineIndexes

	// Search performs a search request to Elastic Search
	Search(ctx context.Context, query *search.Request, indices []string, opts ...elasticxsearch.Option) (*search.Response, error)

	// MultiSearch performs a multi search request to Elastic Search
	MultiSearch(ctx context.Context, items []elasticxmsearch.Item, opts ...elasticxmsearch.Option) (*msearch.Response, error)

	// Bulk performs a bulk request to Elastic Search
	Bulk(ctx context.Context, ops []elasticxbulk.Operation, opts ...elasticxbulk.Option) (*bulk.Response, error)
}

Engine provides access to all indexes in a single engine.

type EngineIndexes

type EngineIndexes interface {
	// Index opens a connection to an exisiting index within the engine.
	// If no index with given name exists, a NotFoundError is returned.
	Index(ctx context.Context, name string) (Index, error)

	// IndexExists returns true if an index with given name exists within the engine.
	IndexExists(ctx context.Context, name string) (bool, error)

	// Indexes returns a list of all indexes in the engine.
	Indexes(ctx context.Context) ([]IndexInfo, error)

	// CreateIndex creates a new index,
	// with given name, and opens a connection to it.
	CreateIndex(ctx context.Context, name string, options *CreateIndexOptions) (Index, error)
}

EngineIndexes provides access to all indexes in a single engine.

type EngineInfo

type EngineInfo struct {
	// The name of the engine.
	Name string `json:"name,omitempty"`
}

type Index

type Index interface {
	// Name returns the name of the index.
	Info() IndexInfo

	// Engine returns the engine containing the index.
	Engine() Engine

	// Remove removes the entire index.
	// If the index does not exists, a NotFoundError is returned.
	Remove(ctx context.Context) error

	// UpdateMappings updates the index mappings.
	UpdateMappings(ctx context.Context, mappings *types.TypeMapping) error

	// All document functions
	IndexDocuments
}

Index provides access to the information of an index.

type IndexDocuments

type IndexDocuments interface {
	// DocumentExists checks if a document with given id exists in the index.
	DocumentExists(ctx context.Context, id string) (bool, error)

	// ReadDocument reads a single document with given id from the index.
	// The document data is stored into result, the document metadata is returned.
	// If no document exists with given id, a NotFoundError is returned.
	ReadDocument(ctx context.Context, id string, result interface{}) (*DocumentMeta, error)

	// CreateDocument creates a single document in the index.
	// The document data is loaded from the given document, the document metadata is returned.
	// If the document data already contains a `_key` field, this will be used as key of the new document,
	// otherwise a unique key is created.
	CreateDocument(ctx context.Context, document interface{}, opts ...DocumentOption) (*DocumentMeta, error)

	// UpsertDocument upserts a single document with given key in the collection with the document given in the document argument.
	// The document metadata is returned.
	UpsertDocument(ctx context.Context, key string, document interface{}, opts ...DocumentOption) (*UpsertResponse[DocumentMeta], error)

	// DeleteDocument deletes a single document with given key in the collection.
	// No error is returned when the document is successfully deleted.
	// If no document exists with given key, a NotFoundError is returned.
	DeleteDocument(ctx context.Context, key string, opts ...DocumentOption) error

	// DeleteDocumentsByQuery deletes all documents satisfying the query.
	// No error is returned when the documents are deleted
	// If the query fails, an error is returned.
	// The number of deleted document and the async taskId is returned.
	DeleteDocumentsByQuery(ctx context.Context, query *types.Query, opts ...DocumentOption) (*DeleteQueryResponse, error)
}

type IndexInfo added in v0.0.27

type IndexInfo struct {
	Name string `json:"name"`
}

type IndexName added in v0.0.27

type IndexName string

func NewIndexName added in v0.0.27

func NewIndexName(elements ...string) IndexName

func (IndexName) Elements added in v0.0.27

func (i IndexName) Elements() []string

func (IndexName) EngineName added in v0.0.27

func (i IndexName) EngineName() string

func (IndexName) Name added in v0.0.27

func (i IndexName) Name() string

func (IndexName) String added in v0.0.27

func (i IndexName) String() string

type TaskId added in v0.0.71

type TaskId any

string or int

type UpsertResponse added in v0.0.70

type UpsertResponse[T any] struct {
	Result UpsertResult `json:"result"`
	Meta   T            `json:"meta"`
}

type UpsertResult added in v0.0.70

type UpsertResult string
const (
	UpsertResultCreated UpsertResult = "created"
	UpsertResultUpdated UpsertResult = "updated"
)

func (UpsertResult) Created added in v0.0.70

func (ur UpsertResult) Created() bool

func (UpsertResult) String added in v0.0.70

func (ur UpsertResult) String() string

func (UpsertResult) Updated added in v0.0.70

func (ur UpsertResult) Updated() bool

Directories

Path Synopsis
Package migration allows to perform versioned migrations in your ElasticEngine.
Package migration allows to perform versioned migrations in your ElasticEngine.

Jump to

Keyboard shortcuts

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