elasticsearch

package
v1.2.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NewClientError               error
	IndexError                   error
	ResIsError                   bool
	ResBodyDecodeParseError      error
	ResBodyDecodeGetIndexedError error
	SearchError                  error
	NewBulkIndexerError          error
	IndexerAddError              error
	IndexerCloseError            error
	IndexerStatsNumFailed        uint64
)

Functions

func InitializeContext

func InitializeContext(ctx context.Context) context.Context

InitializeContext adds the elasticsearch session to the context. The new context is returned because context is immutable.

Types

type ClientFunctions added in v0.16.0

type ClientFunctions interface {
	NewClient(
		config elasticsearch.Config,
	) (*elasticsearch.Client, error)
	Index(
		ctx context.Context,
		client *elasticsearch.Client,
		index, data string,
	) (*esapi.Response, error)
	Search(
		ctx context.Context,
		client *elasticsearch.Client,
		index string,
		body string,
	) (*esapi.Response, error)
	ResBodyClose(res *esapi.Response)
	ResIsError(res *esapi.Response) bool
	ResBodyDecode(res *esapi.Response, v interface{}) error
	NewBulkIndexer(
		client *elasticsearch.Client,
	) (esutil.BulkIndexer, error)
	IndexerAdd(ctx context.Context,
		indexer esutil.BulkIndexer,
		document *IndexedDocument,
		correlator string,
	) error
	IndexerClose(ctx context.Context, indexer esutil.BulkIndexer) error
	IndexerStats(indexer esutil.BulkIndexer) esutil.BulkIndexerStats
}

type ClientService added in v0.16.0

type ClientService struct{}

func NewElasticsearchClientService added in v0.16.0

func NewElasticsearchClientService() *ClientService

func (ClientService) Index added in v0.16.0

func (c ClientService) Index(
	ctx context.Context,
	client *elasticsearch.Client,
	index, data string,
) (*esapi.Response, error)

func (ClientService) IndexerAdd added in v0.16.0

func (c ClientService) IndexerAdd(
	ctx context.Context,
	indexer esutil.BulkIndexer,
	document *IndexedDocument,
	correlator string,
) error

func (ClientService) IndexerClose added in v0.16.0

func (c ClientService) IndexerClose(ctx context.Context, indexer esutil.BulkIndexer) error

func (ClientService) IndexerStats added in v0.16.0

func (c ClientService) IndexerStats(indexer esutil.BulkIndexer) esutil.BulkIndexerStats

func (ClientService) NewBulkIndexer added in v0.16.0

func (c ClientService) NewBulkIndexer(
	client *elasticsearch.Client,
) (esutil.BulkIndexer, error)

func (ClientService) NewClient added in v0.16.0

func (c ClientService) NewClient(
	config elasticsearch.Config,
) (*elasticsearch.Client, error)

func (ClientService) ResBodyClose added in v0.16.0

func (c ClientService) ResBodyClose(res *esapi.Response)

func (ClientService) ResBodyDecode added in v0.16.0

func (c ClientService) ResBodyDecode(res *esapi.Response, v interface{}) error

func (ClientService) ResIsError added in v0.16.0

func (c ClientService) ResIsError(res *esapi.Response) bool

func (ClientService) Search added in v0.16.0

func (c ClientService) Search(
	ctx context.Context,
	client *elasticsearch.Client,
	index string,
	body string,
) (*esapi.Response, error)

type ClientServiceFuncMock added in v0.16.0

type ClientServiceFuncMock struct{}

func (ClientServiceFuncMock) Index added in v0.16.0

func (c ClientServiceFuncMock) Index(
	ctx context.Context,
	client *elasticsearch.Client,
	index, data string,
) (*esapi.Response, error)

func (ClientServiceFuncMock) IndexerAdd added in v0.16.0

func (c ClientServiceFuncMock) IndexerAdd(
	ctx context.Context,
	indexer esutil.BulkIndexer,
	document *IndexedDocument,
	correlator string,
) error

func (ClientServiceFuncMock) IndexerClose added in v0.16.0

func (c ClientServiceFuncMock) IndexerClose(
	ctx context.Context,
	indexer esutil.BulkIndexer,
) error

func (ClientServiceFuncMock) IndexerStats added in v0.16.0

func (ClientServiceFuncMock) NewBulkIndexer added in v0.16.0

func (c ClientServiceFuncMock) NewBulkIndexer(
	client *elasticsearch.Client,
) (esutil.BulkIndexer, error)

func (ClientServiceFuncMock) NewClient added in v0.16.0

func (c ClientServiceFuncMock) NewClient(
	config elasticsearch.Config,
) (*elasticsearch.Client, error)

func (ClientServiceFuncMock) ResBodyClose added in v0.16.0

func (c ClientServiceFuncMock) ResBodyClose(res *esapi.Response)

func (ClientServiceFuncMock) ResBodyDecode added in v0.16.0

func (c ClientServiceFuncMock) ResBodyDecode(res *esapi.Response, v interface{}) error

func (ClientServiceFuncMock) ResIsError added in v0.16.0

func (c ClientServiceFuncMock) ResIsError(res *esapi.Response) bool

func (ClientServiceFuncMock) Search added in v0.16.0

func (c ClientServiceFuncMock) Search(
	ctx context.Context,
	client *elasticsearch.Client,
	index string,
	body string,
) (*esapi.Response, error)

type ContextKey

type ContextKey string

ContextKey defines a type to store the elasticsearch session in context.Context.

type IndexedDocument

type IndexedDocument struct {
	Index string `json:"_index"`
	ID    string `json:"_id"`
}

IndexedDocument represents an Elasticsearch response of an index request with indexed document information.

type Logger

type Logger struct {
	Log *golium.Logger
}

Logger logs the elasticsearch requests and responses in a configurable file.

func GetLogger

func GetLogger() *Logger

GetLogger returns the logger for elasticsearch requests and responses. If the logger is not created yet, it creates a new instance of Logger.

func (Logger) LogCreateIndex

func (l Logger) LogCreateIndex(res *esapi.Response, document, index, corr string)

LogCreateIndex logs a creation in elasticsearch in the configured log file.

func (Logger) LogError

func (l Logger) LogError(err error, corr string)

LogError logs a creation in elasticsearch in the configured log file.

func (Logger) LogSearchIndex

func (l Logger) LogSearchIndex(res *esapi.Response, body, index, corr string)

LogSearchIndex logs a search in elasticsearch in the configured log file.

type Response

type Response struct {
	Error ResponseError `json:"error"`
}

Response represents the body of an elasticsearch response

type ResponseError

type ResponseError struct {
	Type   string `json:"type"`
	Reason string `json:"reason"`
}

ResponseError represents the error information in elasticsearch response

type Session

type Session struct {
	Client       *elasticsearch.Client
	SearchResult golium.Map
	Correlator   string

	ESServiceClient ClientFunctions
	// contains filtered or unexported fields
}

Session contains the information of a elasticsearch session.

func GetSession

func GetSession(ctx context.Context) *Session

GetSession returns the elasticsearch session stored in context. Note that the context should be previously initialized with InitializeContext function.

func (*Session) CleanUp

func (s *Session) CleanUp(ctx context.Context)

CleanUp cleans session by deleting all indexed documents in Elasticsearch

func (*Session) ConfigureClient

func (s *Session) ConfigureClient(ctx context.Context, config elasticsearch.Config) error

ConfigureClient creates a elasticsearch connection based on the URI.

func (*Session) NewDocument

func (s *Session) NewDocument(
	ctx context.Context,
	index string,
	props map[string]interface{},
) error

NewDocument creates a new document, with the given JSON and for the given index.

func (*Session) SearchDocument

func (s *Session) SearchDocument(
	ctx context.Context,
	index string,
	body string,
) error

SearchDocument searches in elasticsearch with given index and JSON body and saves the result in the application context.

func (*Session) ValidateDocumentJSONProperties

func (s *Session) ValidateDocumentJSONProperties(
	ctx context.Context,
	props map[string]interface{},
) error

ValidateDocumentJSONProperties validates that the search result in the application context has the given properties.

type Steps

type Steps struct {
}

Steps type is responsible to initialize the Elasticsearch client steps in godog framework.

func (Steps) InitializeSteps

func (s Steps) InitializeSteps(ctx context.Context, scenCtx *godog.ScenarioContext) context.Context

InitializeSteps adds client elasticsearch steps to the scenario context. It implements StepsInitializer interface. It returns a new context (context is immutable) with the elasticsearch Context.

Jump to

Keyboard shortcuts

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