Documentation
¶
Overview ¶
Package query contains methods for building Elasticsearch queries.
Index ¶
- Constants
- func Build(options ...Option) *types.Query
- type BoolOption
- type MoreLikeThisQuery
- type NumberRangeOption
- type Option
- func Before(field string, before time.Time) Option
- func Between(field string, from time.Time, to time.Time) Option
- func Bool(options ...BoolOption) Option
- func Distance(field, pivot, origin string) Option
- func Exists(field string) Option
- func Match(field, fuzziness string, value string) Option
- func MatchAll() Option
- func MultiMatch(value, fuzziness string, fields ...string) Option
- func MultiMatchPrefix(value string, fields ...string) Option
- func NumberRange(field string, options ...NumberRangeOption) Option
- func SearchAsYouType(text string, field string) Option
- func SimpleQueryString(options ...SimpleQueryStringOption) Option
- func Since(field string, since time.Time) Option
- func Term(field string, value any) Option
- func Terms[T any](field string, values ...T) Option
- type SimpleQueryStringOption
Constants ¶
const FuzzinessAuto = "AUTO"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BoolOption ¶
BoolOption is a functional option for a boolean query.
func Filter ¶
func Filter(queryOptions ...Option) BoolOption
Filter sets the given query options as the "filter" clause of the bool query.
The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching. Each query defined under a filter acts as a logical "AND", returning only documents that match all the specified queries.
func Must ¶
func Must(queryOptions ...Option) BoolOption
Must sets the given query options as the "must" clause of the bool query.
The clause (query) must appear in matching documents and will contribute to the score. Each query defined under a must acts as a logical "AND", returning only documents that match all the specified queries.
func MustNot ¶
func MustNot(queryOptions ...Option) BoolOption
MustNot sets the given query options as the "must_not" clause of the bool query.
The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned. Each query defined under a must_not acts as a logical "NOT", returning only documents that do not match any of the specified queries.
func Should ¶
func Should(queryOptions ...Option) BoolOption
Should sets the given query options as the "should" clause of the bool query.
The clause (query) should appear in the matching document. Each query defined under a should acts as a logical "OR", returning documents that match any of the specified queries.
func WithBoolQueryBoost ¶
func WithBoolQueryBoost(boost float32) BoolOption
WithBoolQueryBoost option adds the given boost to the bool query. tracking when this bool clause matches documents.
func WithBoolQueryName ¶
func WithBoolQueryName(name string) BoolOption
WithBoolQueryName option assigns the given string as the name of the query, which allows tracking when this bool clause matches documents.
type MoreLikeThisQuery ¶
type MoreLikeThisQuery struct {
*types.MoreLikeThisQuery
}
MoreLikeThisQuery represents a "More Like This" query.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-mlt-query
func NewMoreLikeThisQuery ¶
func NewMoreLikeThisQuery(id string) *MoreLikeThisQuery
NewMoreLikeThisQuery creates a new object for generating a More Like This query. It can be used to build/add options for the query.
func (*MoreLikeThisQuery) LikeDocs ¶
func (mlt *MoreLikeThisQuery) LikeDocs(ids ...string)
LikeDocs adds the given document IDs to the More Like This query for matching.
func (*MoreLikeThisQuery) ToQueryOption ¶
func (mlt *MoreLikeThisQuery) ToQueryOption() Option
ToQueryOption adds the More Like This query to the query object.
type NumberRangeOption ¶
type NumberRangeOption func(*types.NumberRangeQuery)
NumberRangeOption is a functional option for a number range query.
func IntLessThan ¶
func IntLessThan(value int64) NumberRangeOption
IntLessThan creates a range option to retrieve documents with the field value less than the given int.
type Option ¶
Option is a functional option for queries.
func Before ¶ added in v0.40.0
Before adds a "Range" query to find documents older than the given time.
func Between ¶
Between adds a "Range" query to find documents between (or equal to) the given times.
func Bool ¶
func Bool(options ...BoolOption) Option
Bool constructs a bool query with the given query options and adds it to the query.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
func Distance ¶
Distance adds a Distance Feature query.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-distance-feature-query
func Exists ¶
Exists query adds an "Exists" clause.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-exists-query
func Match ¶
Match adds a "Match" query on the given field with the given value.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-match-query
func MatchAll ¶
func MatchAll() Option
MatchAll adds a "Match All" clause.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html
func MultiMatch ¶
MultiMatch adds a "MultiMatch" query on the given field with the given value.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-multi-match-query
func MultiMatchPrefix ¶ added in v0.28.1
MultiMatchPrefix adds a "MultiMatch" query on the given field with the given value and performing a phrase_prefix search.
func NumberRange ¶
func NumberRange(field string, options ...NumberRangeOption) Option
NumberRange constructs a bool query with the given query options and adds it to the query.
func SearchAsYouType ¶
SearchAsYouType constructs a search-as-you-type query for suggesting text as the user types.
https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/search-as-you-type
func SimpleQueryString ¶
func SimpleQueryString(options ...SimpleQueryStringOption) Option
SimpleQueryString constructs a simple query string query and adds it to the query.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-simple-query-string-query
func Term ¶
Term adds a "Term" query on the given field with the given value.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
type SimpleQueryStringOption ¶ added in v0.60.0
type SimpleQueryStringOption func(*types.SimpleQueryStringQuery)
SimpleQueryStringOption is a functional option for building a SimpleQueryString query.
func WithSimpleQueryStringFields ¶ added in v0.60.0
func WithSimpleQueryStringFields(fields ...string) SimpleQueryStringOption
WithSimpleQueryStringFields option specifies the fields to query.
func WithSimpleQueryStringName ¶ added in v0.60.0
func WithSimpleQueryStringName(name string) SimpleQueryStringOption
WithSimpleQueryStringName option assigns a name to the query.
func WithSimpleQueryStringOperator ¶ added in v0.60.0
func WithSimpleQueryStringOperator(op *operator.Operator) SimpleQueryStringOption
WithSimpleQueryStringOperator option sets the default operator for the SimpleQueryString query. If not used, the default is OR.
func WithSimpleQueryStringText ¶ added in v0.60.0
func WithSimpleQueryStringText(text *string) SimpleQueryStringOption
WithSimpleQueryStringText option specifies the query text.