espoll

package
v0.0.0-...-94836cd Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package espoll wraps an elasticsearch.Client to provide utilitarian methods to assert for conditions until a certain threshold is met.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolQuery

type BoolQuery struct {
	Filter             []any
	Must               []any
	MustNot            []any
	Should             []any
	MinimumShouldMatch int
	Boost              float64
}

func (BoolQuery) MarshalJSON

func (q BoolQuery) MarshalJSON() ([]byte, error)

type Client

type Client struct {
	*elasticsearch.Client
}

Client wraps an Elasticsearch client

func WrapClient

func WrapClient(c *elasticsearch.Client) *Client

WrapClient wraps an Elasticsearch client and returns an espoll.Client

func (*Client) Do

func (es *Client) Do(
	ctx context.Context,
	req Request,
	out any,
	opts ...RequestOption,
) (*esapi.Response, error)

Do performs the specified request.

func (*Client) NewSearchRequest

func (es *Client) NewSearchRequest(index string) *SearchRequest

NewSearchRequest returns a search request using the wrapped Elasticsearch client.

func (*Client) SearchIndexMinDocs

func (es *Client) SearchIndexMinDocs(
	ctx context.Context,
	min int, index string,
	query json.Marshaler,
	opts ...RequestOption,
) (SearchResult, error)

SearchIndexMinDocs searches index with query, returning the results.

If the search returns fewer than min results within 10 seconds (by default), SearchIndexMinDocs will return an error.

type ConditionFunc

type ConditionFunc func(*esapi.Response) bool

ConditionFunc evaluates the esapi.Response.

func AllCondition

func AllCondition(conds ...ConditionFunc) ConditionFunc

AllCondition returns a ConditionFunc that returns true as long as none of the supplied conditions returns false.

type Error

type Error struct {
	StatusCode int
	Message    string
}

func (*Error) Error

func (e *Error) Error() string

type ExistsQuery

type ExistsQuery struct {
	Field string
}

func (ExistsQuery) MarshalJSON

func (q ExistsQuery) MarshalJSON() ([]byte, error)

type MatchPhraseQuery

type MatchPhraseQuery struct {
	Field string
	Value any
}

func (MatchPhraseQuery) MarshalJSON

func (q MatchPhraseQuery) MarshalJSON() ([]byte, error)

type Request

type Request interface {
	Do(ctx context.Context, transport esapi.Transport) (*esapi.Response, error)
}

type RequestOption

type RequestOption func(*requestOptions)

RequestOption modifies certain parameters for an esapi.Request.

func WithCondition

func WithCondition(cond ConditionFunc) RequestOption

WithCondition runs the specified condition func.

func WithInterval

func WithInterval(d time.Duration) RequestOption

WithInterval sets the poll interval in an Elasticsearch request.

func WithTimeout

func WithTimeout(d time.Duration) RequestOption

WithTimeout sets the timeout in an Elasticsearch request.

type SearchHit

type SearchHit struct {
	Index     string
	ID        string
	Score     float64
	Fields    map[string][]any
	Source    map[string]any
	RawSource json.RawMessage
	RawFields json.RawMessage
}

func (*SearchHit) UnmarshalJSON

func (h *SearchHit) UnmarshalJSON(data []byte) error

func (*SearchHit) UnmarshalSource

func (h *SearchHit) UnmarshalSource(out any) error

type SearchHits

type SearchHits struct {
	Total SearchHitsTotal `json:"total"`
	Hits  []SearchHit     `json:"hits"`
}

func (*SearchHits) MinHitsCondition

func (h *SearchHits) MinHitsCondition(min int) ConditionFunc

MinHitsCondition returns a ConditionFunc which will return true if the number of h.Hits is at least min.

func (*SearchHits) NonEmptyCondition

func (h *SearchHits) NonEmptyCondition() ConditionFunc

NonEmptyCondition returns a ConditionFunc which will return true if h.Hits is non-empty.

func (*SearchHits) TotalHitsCondition

func (h *SearchHits) TotalHitsCondition(req *SearchRequest) ConditionFunc

TotalHitsCondition returns a ConditionFunc which will return true if the number of h.Hits is at least h.Total.Value. If the condition returns false, it will update req.Size to accommodate the number of hits in the following search.

type SearchHitsTotal

type SearchHitsTotal struct {
	Value    int    `json:"value"`
	Relation string `json:"relation"` // "eq" or "gte"
}

type SearchRequest

type SearchRequest struct {
	esapi.SearchRequest
	// contains filtered or unexported fields
}

SearchRequest wraps an esapi.SearchRequest with a Client.

func (*SearchRequest) Do

func (*SearchRequest) WithQuery

func (r *SearchRequest) WithQuery(q any) *SearchRequest

func (*SearchRequest) WithSize

func (r *SearchRequest) WithSize(size int) *SearchRequest

func (*SearchRequest) WithSort

func (r *SearchRequest) WithSort(fieldDirection ...string) *SearchRequest

type SearchResult

type SearchResult struct {
	Hits         SearchHits                 `json:"hits"`
	Aggregations map[string]json.RawMessage `json:"aggregations"`
}

type TermQuery

type TermQuery struct {
	Field string
	Value any
	Boost float64
}

func (TermQuery) MarshalJSON

func (q TermQuery) MarshalJSON() ([]byte, error)

type TermsQuery

type TermsQuery struct {
	Field  string
	Values []any
	Boost  float64
}

func (TermsQuery) MarshalJSON

func (q TermsQuery) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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