Documentation ¶
Overview ¶
Package espoll wraps an elasticsearch.Client to provide utilitarian methods to assert for conditions until a certain threshold is met.
Index ¶
- type BoolQuery
- type Client
- func (es *Client) Do(ctx context.Context, req Request, out any, opts ...RequestOption) (*esapi.Response, error)
- func (es *Client) NewSearchRequest(index string) *SearchRequest
- func (es *Client) SearchIndexMinDocs(ctx context.Context, min int, index string, query json.Marshaler, ...) (SearchResult, error)
- type ConditionFunc
- type Error
- type ExistsQuery
- type MatchPhraseQuery
- type Request
- type RequestOption
- type SearchHit
- type SearchHits
- type SearchHitsTotal
- type SearchRequest
- func (r *SearchRequest) Do(ctx context.Context, out *SearchResult, opts ...RequestOption) (*esapi.Response, error)
- func (r *SearchRequest) WithQuery(q any) *SearchRequest
- func (r *SearchRequest) WithSize(size int) *SearchRequest
- func (r *SearchRequest) WithSort(fieldDirection ...string) *SearchRequest
- type SearchResult
- type TermQuery
- type TermsQuery
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 ¶
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 ¶
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 ExistsQuery ¶
type ExistsQuery struct {
Field string
}
func (ExistsQuery) MarshalJSON ¶
func (q ExistsQuery) MarshalJSON() ([]byte, error)
type MatchPhraseQuery ¶
func (MatchPhraseQuery) MarshalJSON ¶
func (q MatchPhraseQuery) MarshalJSON() ([]byte, 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 (*SearchHit) UnmarshalSource ¶
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 SearchRequest ¶
type SearchRequest struct { esapi.SearchRequest // contains filtered or unexported fields }
SearchRequest wraps an esapi.SearchRequest with a Client.
func (*SearchRequest) Do ¶
func (r *SearchRequest) Do(ctx context.Context, out *SearchResult, opts ...RequestOption) (*esapi.Response, error)
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 ¶
func (TermQuery) MarshalJSON ¶
type TermsQuery ¶
func (TermsQuery) MarshalJSON ¶
func (q TermsQuery) MarshalJSON() ([]byte, error)