elasticsearch

package
v0.5.7-rc.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ESError{
	StatusCode: 404,
	Message:    "Object not found",
}

Functions

This section is empty.

Types

type AggResults

type AggResults struct {
	Buckets []Bucket
	Total   int
}

AggResults is assumed to be a struct that holds aggregation results.

type Bucket

type Bucket struct {
	Keys  []string
	Count int
}

Bucket is assumed to be a struct that holds individual bucket data.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents an Elasticsearch client that can perform various operations on the Elasticsearch cluster.

func NewClient

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

NewClient creates a new Elasticsearch client instance

func (*Client) AggregateDocumentByTerms

func (cl *Client) AggregateDocumentByTerms(ctx context.Context, index string, fields []string) (*AggResults, error)

AggregateDocumentByTerms performs an aggregation query based on the provided fields.

func (*Client) CheckElasticSearchLiveness added in v0.4.8

func (cl *Client) CheckElasticSearchLiveness(ctx context.Context) error

CheckElasticSearchLiveness would ping ElasticSearch client

func (*Client) Count

func (cl *Client) Count(
	ctx context.Context,
	indexName string,
) (*CountResponse, error)

Count performs a count query in the specified index.

func (*Client) CreateIndex

func (cl *Client) CreateIndex(ctx context.Context, index string, body io.Reader) error

CreateIndex creates a new index with the specified settings and mappings

func (*Client) DeleteDocument

func (cl *Client) DeleteDocument(ctx context.Context, indexName, documentID string) error

DeleteDocument deletes a document with the specified ID

func (*Client) DeleteDocumentByQuery

func (cl *Client) DeleteDocumentByQuery(
	ctx context.Context,
	indexName string,
	body io.Reader,
) error

DeleteDocumentByQuery deletes documents from the specified index based on the provided query in the body.

func (*Client) GetDocument

func (cl *Client) GetDocument(
	ctx context.Context,
	indexName string,
	documentID string,
) (map[string]interface{}, error)

GetDocument gets a document with the specified ID

func (*Client) IsIndexExists

func (cl *Client) IsIndexExists(ctx context.Context, index string) (bool, error)

IsIndexExists Check if an index exists in Elasticsearch

func (*Client) Refresh

func (cl *Client) Refresh(
	ctx context.Context,
	indexName string,
) error

Refresh refresh specified index in Elasticsearch.

func (*Client) SaveDocument

func (cl *Client) SaveDocument(
	ctx context.Context,
	indexName string,
	documentID string,
	body io.Reader,
) error

SaveDocument saves a new document

func (*Client) SearchDocument

func (cl *Client) SearchDocument(
	ctx context.Context,
	indexName string,
	body io.Reader,
	options ...Option,
) (*SearchResponse, error)

SearchDocument performs a search query in the specified index

func (*Client) SearchDocumentByTerms

func (cl *Client) SearchDocumentByTerms(ctx context.Context, index string, keysAndValues map[string]any, options ...Option) (*SearchResponse, error)

SearchDocumentByTerms constructs a boolean search query with a must term match for each key-value pair in keyAndVal,

func (*Client) UpdateDocument added in v0.5.5

func (cl *Client) UpdateDocument(
	ctx context.Context,
	indexName string,
	documentID string,
	body io.Reader,
) error

UpdateDocument updates a document with the specified ID

type CountResponse

type CountResponse struct {
	Count int64 `json:"count"`
}

CountResponse represents the response structure for a count operation.

type ESError

type ESError struct {
	StatusCode int
	Message    string
}

ESError is an error type which represents a single ES error

func (*ESError) Error

func (e *ESError) Error() string

Error() method implementation for ESError, which returns the error message in a string format.

type Hit

type Hit struct {
	Index  string                 `json:"_index"`
	ID     string                 `json:"_id"`
	Score  float32                `json:"_score"`
	Source map[string]interface{} `json:"_source"`
}

Hit represents a single hit document from a search operation, containing index, ID, score, and source data.

type Hits

type Hits struct {
	Total    *Total  `json:"total"`
	MaxScore float32 `json:"max_score"`
	Hits     []*Hit  `json:"hits"`
}

Hits contains the hit documents and metadata from a search operation.

type Option

type Option func(*config) error

func Pagination

func Pagination(page, pageSize int) Option

Pagination is a functional option to set the pagination configuration.

type SearchResponse

type SearchResponse struct {
	ScrollID string `json:"_scroll_id"`
	Took     int    `json:"took"`
	TimeOut  bool   `json:"time_out"`
	Hits     *Hits  `json:"hits"`
}

SearchResponse represents the response structure for a search operation.

type Total

type Total struct {
	Value    int    `json:"value,omitempty"`
	Relation string `json:"relation,omitempty"`
}

Total provides information about the total number of documents matching the search query.

Jump to

Keyboard shortcuts

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