elasticx

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsAlphanumeric = regexp.MustCompile("^[a-zA-Z0-9]*$").MatchString
View Source
var IsLetter = regexp.MustCompile(`^[a-zA-Z]+$`).MatchString

Functions

func IsError

func IsError(r *http.Response) bool

Types

type CatIndex

type CatIndex struct {
	Health       string `json:"health"`
	Status       string `json:"status"`
	Index        string `json:"index"`
	Uuid         string `json:"uuid"`
	Pri          string `json:"pri"`
	Rep          string `json:"rep"`
	DocsCount    string `json:"docs.count"`
	DocsDeleted  string `json:"docs.deleted"`
	StoreSize    string `json:"store.size"`
	PriStoreSize string `json:"pri.store.size"`
}

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) ([]Engine, 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, options *CreateEngineOptions) (Engine, error)
}

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

type CreateEngineOptions

type CreateEngineOptions struct {
}

CreateEngineOptions contains options that customize the creation of a database.

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 DeleteByQueryResponse

type DeleteByQueryResponse struct {
	Took             int  `json:"took"`
	TimedOut         bool `json:"timed_out"`
	Total            int  `json:"total"`
	Deleted          int  `json:"deleted"`
	Batches          int  `json:"batches"`
	VersionConflicts int  `json:"version_conflicts"`
	Noops            int  `json:"noops"`
	Retries          struct {
		Bulk   int `json:"bulk"`
		Search int `json:"search"`
	}
	ThrottledMillis      int               `json:"throttled_millis"`
	RequestsPerSecond    float32           `json:"requests_per_second"`
	ThrottledUntilMillis int               `json:"throttled_until_millis"`
	Failures             []json.RawMessage `json:"failures"`
}

type DocumentMeta

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

type DocumentOptions

type DocumentOptions struct {
	Refresh string
}

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

	// Query performs a search request to Elastic Search
	Query(ctx context.Context, query string, index ...string) (*SearchResponse, error)

	// Queries performs a multi search request to Elastic Search
	Queries(ctx context.Context, queries ...MultiQuery) (map[string]SearchResponse, 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) ([]Index, 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 identifier of the engine.
	ID string `json:"id,omitempty"`
	// The name of the engine.
	Name string `json:"name,omitempty"`
}

type Index

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

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

	// Remove removes the entire index.
	// If the view does not exists, a NotFoundError us returned.
	Remove(ctx context.Context) 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{}, options *DocumentOptions) (*DocumentMeta, error)

	// ReplaceDocument replaces a single document with given key in the collection with the document given in the document argument.
	// The document metadata is returned.
	// If no document exists with given key, a NotFoundError is returned.
	ReplaceDocument(ctx context.Context, key string, document interface{}, options *DocumentOptions) (*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, options *DocumentOptions) error
}

type MultiQuery

type MultiQuery struct {
	Name  string
	Query string
	Index []string
}

type SearchResponse

type SearchResponse struct {
	Took int `json:"took"`
	Hits struct {
		Total struct {
			Value int
		}
		Hits []struct {
			ID         string          `json:"_id"`
			Source     json.RawMessage `json:"_source"`
			Highlights json.RawMessage `json:"highlight"`
			Sort       []interface{}   `json:"sort"`
		}
	}
}

Directories

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

Jump to

Keyboard shortcuts

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