elasticsearch

package
v0.3.7-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 8 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 Client

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

func NewClient

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

NewClient creates a new Elasticsearch client instance

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 string, documentID string) error

DeleteDocument deletes a document with the specified ID

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) 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

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

type Hit

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

type Hits

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

type Option

type Option func(*config) error

func Pagination

func Pagination(page, pageSize int) Option

type SearchResponse

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

type Total

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

Jump to

Keyboard shortcuts

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