es

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SearchExecutionException       = "search_phase_execution_exception"
	TooManyBucketsException        = "too_many_buckets_exception"
	TooManyNestedClausesException  = "too_many_nested_clauses"
	TooManyClausesException        = "too_many_clauses"
	IllegalArgumentException       = "illegal_argument_exception"
	SnapshotInProgressException    = "snapshot_in_progress_exception"
	ResourceAlreadyExistsException = "resource_already_exists_exception"
)

Variables

View Source
var (
	ErrTooManyRequests      = errors.New("too many requests")
	ErrTooManyBuckets       = errors.New("too many buckets")
	ErrTooManyNestedClauses = errors.New("too many nested clauses")
	ErrTooManyClauses       = errors.New("too many clauses")
)
View Source
var (
	ErrResourceNotFound = errors.New("elasticsearch resource not found")
)

Functions

func Ptr

func Ptr[T any](i T) *T

Types

type Aggregation

type Aggregation struct {
	Filter        *Condition             `json:"filter,omitempty"`
	Cardinality   *CardinalityAgg        `json:"cardinality,omitempty"`
	DateHistogram *DateHistogramAgg      `json:"date_histogram,omitempty"`
	Sum           *SumMinMaxAgg          `json:"sum,omitempty"`
	Min           *SumMinMaxAgg          `json:"min,omitempty"`
	Max           *SumMinMaxAgg          `json:"max,omitempty"`
	Avg           *SumMinMaxAgg          `json:"avg,omitempty"`
	Percentiles   *ESPercentilesAgg      `json:"percentiles,omitempty"`
	Terms         *TermsAgg              `json:"terms,omitempty"`
	Histogram     *HistogramAgg          `json:"histogram,omitempty"`
	Aggs          map[string]Aggregation `json:"aggs,omitempty"`
}

type BoolFilter

type BoolFilter struct {
	Filter             []Condition `json:"filter,omitempty"`
	Should             []Condition `json:"should,omitempty"`
	Must               []Condition `json:"must,omitempty"`
	MustNot            []Condition `json:"must_not,omitempty"`
	MinimumShouldMatch int         `json:"minimum_should_match,omitempty"`
}

type BulkIndex

type BulkIndex struct {
	Index       string `json:"_index"`
	ID          string `json:"_id"`
	Version     *int   `json:"version,omitempty"`
	VersionType string `json:"version_type,omitempty"`
}

type BulkItem

type BulkItem struct {
	Index  *BulkIndex      `json:"index,omitempty"`
	Delete *BulkIndex      `json:"delete,omitempty"`
	Doc    map[string]any  `json:"-"`
	Status int             `json:"-"`
	Error  json.RawMessage `json:"-"`
}

type BulkResponse

type BulkResponse struct {
	Errors bool `json:"errors"`
	Items  []BulkResponseItem
}

type BulkResponseItem

type BulkResponseItem struct {
	Index struct {
		Status int             `json:"status"`
		Error  json.RawMessage `json:"error"`
	} `json:"index"`
	Delete struct {
		Status int             `json:"status"`
		Error  json.RawMessage `json:"error"`
	} `json:"delete"`
}

type CardinalityAgg

type CardinalityAgg struct {
	Field              string `json:"field"`
	PrecisionThreshold int    `json:"precision_threshold"`
}

type CausedBy

type CausedBy struct {
	Type       string `mapstructure:"type"`
	Reason     string `mapstructure:"reason"`
	MaxBuckets int    `mapstructure:"max_buckets"`
}

type Client

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

func NewClient

func NewClient(url string) (*Client, error)

func (*Client) CloseIndex

func (ec *Client) CloseIndex(ctx context.Context, index string) error

func (*Client) Count

func (ec *Client) Count(ctx context.Context, index string) (int, error)

func (*Client) CreateIndex

func (ec *Client) CreateIndex(ctx context.Context, index string, body map[string]any) error

func (*Client) DeleteByQuery

func (ec *Client) DeleteByQuery(ctx context.Context, req *DeleteByQueryRequest) error

func (*Client) DeleteIndex

func (ec *Client) DeleteIndex(ctx context.Context, index []string) error

func (*Client) GetIndexAlias

func (ec *Client) GetIndexAlias(ctx context.Context, name string) (map[string]any, error)

func (*Client) GetIndexMappings

func (ec *Client) GetIndexMappings(ctx context.Context, index string) (*Mappings, error)

func (*Client) GetIndicesStats

func (ec *Client) GetIndicesStats(ctx context.Context, indexPattern string) ([]IndexStats, error)

GetIndicesStats uses the index stats API to fetch statistics about indices. indexPattern is a wildcard pattern used to select the indices we care about.

func (*Client) Index

func (ec *Client) Index(ctx context.Context, req *IndexRequest) error

func (*Client) IndexExists

func (ec *Client) IndexExists(ctx context.Context, index string) (bool, error)

func (*Client) IndexWithID

func (ec *Client) IndexWithID(ctx context.Context, req *IndexWithIDRequest) error

func (*Client) ListIndices

func (ec *Client) ListIndices(ctx context.Context, indices []string) ([]string, error)

ListIndices returns the list of indices that match the index name pattern on input from the OS cluster

func (*Client) Perform

func (ec *Client) Perform(req *http.Request) (*http.Response, error)

func (*Client) PutIndexAlias

func (ec *Client) PutIndexAlias(ctx context.Context, index []string, name string) error

func (*Client) PutIndexMappings

func (ec *Client) PutIndexMappings(ctx context.Context, index string, mapping map[string]any) error

PutIndexMappings add field type mapping data to a previously created ES index Dynamic mapping is disabled upon index creation, so it is a requirement to explicitly define mappings for each column

func (*Client) PutIndexSettings

func (ec *Client) PutIndexSettings(ctx context.Context, index string, settings map[string]any) error

func (*Client) RefreshIndex

func (ec *Client) RefreshIndex(ctx context.Context, index string) error

func (*Client) Search

func (ec *Client) Search(ctx context.Context, req *SearchRequest) (*SearchResponse, error)

func (*Client) SendBulkRequest

func (ec *Client) SendBulkRequest(ctx context.Context, items []BulkItem) ([]BulkItem, error)

SendBulkRequest can perform multiple indexing or delete operations in a single call

type Condition

type Condition struct {
	Term       map[string]any `json:"term,omitempty"`
	Terms      map[string]any `json:"terms,omitempty"`
	Prefix     map[string]any `json:"prefix,omitempty"`
	Wildcard   map[string]any `json:"wildcard,omitempty"`
	IDs        map[string]any `json:"ids,omitempty"`
	Range      map[string]any `json:"range,omitempty"`
	Exists     *ExistsFilter  `json:"exists,omitempty"`
	Bool       *BoolFilter    `json:"bool,omitempty"`
	MultiMatch *MultiMatch    `json:"multi_match,omitempty"`
}

type DateHistogramAgg

type DateHistogramAgg struct {
	Field            string  `json:"field"`
	FixedInterval    *string `json:"fixed_interval,omitempty"`
	CalendarInterval *string `json:"calendar_interval,omitempty"`
	TimeZone         *string `json:"time_zone,omitempty"`
	Format           string  `json:"format,omitempty"`
}

type DeleteByQueryRequest

type DeleteByQueryRequest struct {
	Index   []string
	Query   map[string]any
	Refresh bool
}

type ESPercentilesAgg

type ESPercentilesAgg struct {
	Field    string    `json:"field"`
	Percents []float32 `json:"percents"`
}

type ErrIllegalArgument

type ErrIllegalArgument struct {
	Reason string
}

func (*ErrIllegalArgument) Error

func (e *ErrIllegalArgument) Error() string

type ErrQueryInvalid

type ErrQueryInvalid struct {
	Cause error
}

func (ErrQueryInvalid) Error

func (e ErrQueryInvalid) Error() string

type ErrResourceAlreadyExists

type ErrResourceAlreadyExists struct {
	Reason string
}

func (ErrResourceAlreadyExists) Error

func (e ErrResourceAlreadyExists) Error() string

type ExistsFilter

type ExistsFilter struct {
	Field string `json:"field"`
}

type ExpFunction

type ExpFunction struct {
	Origin *string `json:"origin,omitempty"`
	Scale  string  `json:"scale"`
	Decay  float64 `json:"decay"`
}

type FieldValueFactor

type FieldValueFactor struct {
	Field    string  `json:"field"`
	Factor   float32 `json:"factor"`
	Modifier int     `json:"modifier"`
}

type Function

type Function struct {
	Filter           *Condition             `json:"filter,omitempty"`
	FieldValueFactor *FieldValueFactor      `json:"field_value_factor,omitempty"`
	Weight           *float64               `json:"weight,omitempty"`
	Exp              map[string]ExpFunction `json:"exp,omitempty"`
}

type FunctionScore

type FunctionScore struct {
	Query     *Query     `json:"query,omitempty"`
	ScoreMode string     `json:"score_mode,omitempty"`
	BoostMode string     `json:"boost_mode,omitempty"`
	Boost     float64    `json:"boost,omitempty"`
	Functions []Function `json:"functions,omitempty"`
}

type Highlight

type Highlight struct {
	Fields   map[string]any `json:"fields"`
	Encoder  string         `json:"encoder"`
	PreTags  []string       `json:"pre_tags,omitempty"`
	PostTags []string       `json:"post_tags,omitempty"`
}

type HistogramAgg

type HistogramAgg struct {
	Field    string   `json:"field"`
	Interval float64  `json:"interval"`
	Offset   *float64 `json:"offset,omitempty"`
}

type Hit

type Hit struct {
	ID        string         `json:"_id"`
	Index     string         `json:"_index"`
	Version   int            `json:"_version"`
	Source    map[string]any `json:"_source"`
	Score     float64        `json:"_score"`
	Highlight map[string]any `json:"highlight"`
}

type Hits

type Hits struct {
	Total struct {
		Value    int    `json:"value"`
		Relation string `json:"relation"`
	} `json:"total"`
	Hits []Hit `json:"hits"`
}

type IndexRequest

type IndexRequest struct {
	Index   string
	Body    []byte
	Refresh string
}

type IndexStats

type IndexStats struct {
	Index            string `json:"index,omitempty"`
	PrimarySizeBytes uint64 `json:"primary_size_bytes,omitempty"`
	TotalSizeBytes   uint64 `json:"total_size_bytes,omitempty"`
}

type IndexWithIDRequest

type IndexWithIDRequest struct {
	Index   string
	ID      string
	Body    []byte
	Refresh string
}

type KNNQuery

type KNNQuery struct {
	Vector []float32 `json:"vector"`
	K      int       `json:"k"`
}

type Mappings

type Mappings struct {
	Properties map[string]any
	Dynamic    string
}

type MultiMatch

type MultiMatch struct {
	Query         string   `json:"query"`
	Type          string   `json:"type"`
	Fuzziness     int      `json:"fuzziness,omitempty"`
	Fields        []string `json:"fields,omitempty"`
	Lenient       bool     `json:"lenient,omitempty"`
	MaxExpansions int      `json:"max_expansions,omitempty"`
}

type Query

type Query struct {
	Bool          *BoolFilter          `json:"bool,omitempty"`
	FunctionScore *FunctionScore       `json:"function_score,omitempty"`
	ScriptScore   *ScriptScore         `json:"script_score,omitempty"`
	KNN           *map[string]KNNQuery `json:"knn,omitempty"`
}

type QueryBody

type QueryBody struct {
	Query      *Query                  `json:"query,omitempty"`
	Sort       *Sort                   `json:"sort,omitempty"`
	Highlight  *Highlight              `json:"highlight,omitempty"`
	Aggs       *map[string]Aggregation `json:"aggs,omitempty"`
	Size       int                     `json:"size,omitempty"`
	PostFilter *Condition              `json:"post_filter,omitempty"`
}

type ResponseError

type ResponseError struct {
	Type         string           `mapstructure:"type"`
	Reason       string           `mapstructure:"reason"`
	FailedShards []map[string]any `mapstructure:"failed_shards"`
	CausedBy     *CausedBy        `mapstructure:"caused_by"`
	RootCause    []RootCause      `mapstructure:"root_cause"`
}

type RetryableError

type RetryableError struct {
	Cause error
}

func (RetryableError) Error

func (r RetryableError) Error() string

func (RetryableError) Unwrap

func (r RetryableError) Unwrap() error

type RootCause

type RootCause struct {
	Type   string `mapstructure:"type"`
	Reason string `mapstructure:"reason"`
}

type Script

type Script struct {
	Source string         `json:"source"`
	Lang   string         `json:"lang"`
	Params map[string]any `json:"params,omitempty"`
}

type ScriptScore

type ScriptScore struct {
	Query  json.RawMessage `json:"query,omitempty"`
	Script *Script         `json:"script,omitempty"`
}

type SearchClient

type SearchClient interface {
	CloseIndex(ctx context.Context, index string) error
	Count(ctx context.Context, index string) (int, error)
	CreateIndex(ctx context.Context, index string, body map[string]any) error
	DeleteByQuery(ctx context.Context, req *DeleteByQueryRequest) error
	DeleteIndex(ctx context.Context, index []string) error
	GetIndexAlias(ctx context.Context, name string) (map[string]any, error)
	GetIndexMappings(ctx context.Context, index string) (*Mappings, error)
	GetIndicesStats(ctx context.Context, indexPattern string) ([]IndexStats, error)
	Index(ctx context.Context, req *IndexRequest) error
	IndexWithID(ctx context.Context, req *IndexWithIDRequest) error
	IndexExists(ctx context.Context, index string) (bool, error)
	ListIndices(ctx context.Context, indices []string) ([]string, error)
	Perform(req *http.Request) (*http.Response, error)
	PutIndexAlias(ctx context.Context, index []string, name string) error
	PutIndexMappings(ctx context.Context, index string, body map[string]any) error
	PutIndexSettings(ctx context.Context, index string, body map[string]any) error
	RefreshIndex(ctx context.Context, index string) error
	Search(ctx context.Context, req *SearchRequest) (*SearchResponse, error)
	SendBulkRequest(ctx context.Context, items []BulkItem) ([]BulkItem, error)
}

type SearchRequest

type SearchRequest struct {
	Index          *string
	ReturnVersion  *bool
	Size           *int
	From           *int
	Sort           *string
	SourceIncludes *string
	Query          io.Reader
}

type SearchResponse

type SearchResponse struct {
	Hits         Hits           `json:"hits"`
	Aggregations map[string]any `json:"aggregations"`
}

type Sort

type Sort []map[string]any

type SumMinMaxAgg

type SumMinMaxAgg struct {
	Field string `json:"field"`
}

type TermsAgg

type TermsAgg struct {
	Field string `json:"field"`
	Size  int    `json:"size"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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