Documentation
¶
Overview ¶
Package query contains methods for building Elasticsearch queries.
Index ¶
- func Build(options ...Option) *types.Query
- func WithFuzziness[T Fuzziness](fuzziness FuzzinessValue) func(T)
- func WithFuzzyTranspositions[T Fuzziness](value bool) func(T)
- func WithQueryBoost[T Boostable](boost float32) func(T)
- func WithQueryName[T Nameable](name string) func(T)
- func WithSlop[T Sloppiness](slop int) func(T)
- func WithTextQueryType[T TextQueryTypes](tq TextQueryType) func(T)
- type BoolOption
- type Boostable
- type ExistsQuery
- type Fuzziness
- type FuzzinessValue
- type MatchAllQuery
- type MatchPhraseQuery
- type MatchQuery
- type MoreLikeThisQuery
- type MultiMatchQuery
- func (q *MultiMatchQuery) SetBoost(boost float32)
- func (q *MultiMatchQuery) SetFuzziness(fuzziness FuzzinessValue)
- func (q *MultiMatchQuery) SetFuzzyTranspositions(value bool)
- func (q *MultiMatchQuery) SetName(name string)
- func (q *MultiMatchQuery) SetSlop(slop int)
- func (q *MultiMatchQuery) SetTextQueryType(tq TextQueryType)
- type Nameable
- 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, options ...func(*ExistsQuery)) Option
- func Match(field, value string, options ...func(*MatchQuery)) Option
- func MatchAll(options ...func(*MatchAllQuery)) Option
- func MatchPhrase(field, value string, options ...func(*MatchPhraseQuery)) Option
- func MultiMatch(value string, fields []string, options ...func(*MultiMatchQuery)) 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, options ...func(*TermQuery)) Option
- func Terms[T any](field string, values []T, options ...func(*TermsQuery)) Option
- func Wildcard(field string, value string, options ...func(*WildcardQuery)) Option
- type SimpleQueryStringOption
- type Sloppiness
- type TermQuery
- type TermsQuery
- type TextQueryType
- type TextQueryTypes
- type WildcardQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithFuzziness ¶ added in v0.120.0
func WithFuzziness[T Fuzziness](fuzziness FuzzinessValue) func(T)
WithFuzziness applies the given fuzziness to this query option.
func WithFuzzyTranspositions ¶ added in v0.120.0
WithFuzzyTranspositions allows edits for fuzzy matching include transpositions of two adjacent characters (ab → ba). Defaults to true if not set.
func WithQueryBoost ¶ added in v0.120.0
WithQueryBoost applies a boost to this query option.
func WithQueryName ¶ added in v0.120.0
WithQueryName assigns the given name to this query option.
func WithSlop ¶ added in v0.120.0
func WithSlop[T Sloppiness](slop int) func(T)
WithSlop defines the maximum number of positions allowed between matching tokens.
func WithTextQueryType ¶ added in v0.120.0
func WithTextQueryType[T TextQueryTypes](tq TextQueryType) func(T)
WithTextQueryType changes the operating mode of the text query.
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 Boostable ¶ added in v0.120.0
type Boostable interface {
*TermQuery | *TermsQuery | *ExistsQuery | *MatchAllQuery | *MatchQuery | *MatchPhraseQuery | *MultiMatchQuery | *WildcardQuery
SetBoost(boost float32)
}
Boostable represents a query option that supports a boost parameter.
type ExistsQuery ¶ added in v0.120.0
type ExistsQuery struct {
*types.ExistsQuery
}
func (*ExistsQuery) SetBoost ¶ added in v0.120.0
func (q *ExistsQuery) SetBoost(boost float32)
func (*ExistsQuery) SetName ¶ added in v0.120.0
func (q *ExistsQuery) SetName(name string)
type Fuzziness ¶ added in v0.120.0
type Fuzziness interface {
*MatchQuery | *MultiMatchQuery
SetFuzziness(fuzziness FuzzinessValue)
SetFuzzyTranspositions(value bool)
}
Fuzziness represents a query option that supports setting fuzziness.
type FuzzinessValue ¶ added in v0.120.0
type MatchAllQuery ¶ added in v0.120.0
type MatchAllQuery struct {
*types.MatchAllQuery
}
func (*MatchAllQuery) SetBoost ¶ added in v0.120.0
func (q *MatchAllQuery) SetBoost(boost float32)
func (*MatchAllQuery) SetName ¶ added in v0.120.0
func (q *MatchAllQuery) SetName(name string)
type MatchPhraseQuery ¶ added in v0.130.0
type MatchPhraseQuery struct {
*types.MatchPhraseQuery
}
func (*MatchPhraseQuery) SetBoost ¶ added in v0.130.0
func (q *MatchPhraseQuery) SetBoost(boost float32)
func (*MatchPhraseQuery) SetName ¶ added in v0.130.0
func (q *MatchPhraseQuery) SetName(name string)
func (*MatchPhraseQuery) SetSlop ¶ added in v0.130.0
func (q *MatchPhraseQuery) SetSlop(slop int)
type MatchQuery ¶ added in v0.120.0
type MatchQuery struct {
*types.MatchQuery
}
func (*MatchQuery) SetBoost ¶ added in v0.120.0
func (q *MatchQuery) SetBoost(boost float32)
func (*MatchQuery) SetFuzziness ¶ added in v0.120.0
func (q *MatchQuery) SetFuzziness(fuzziness FuzzinessValue)
func (*MatchQuery) SetFuzzyTranspositions ¶ added in v0.120.0
func (q *MatchQuery) SetFuzzyTranspositions(value bool)
func (*MatchQuery) SetName ¶ added in v0.120.0
func (q *MatchQuery) SetName(name string)
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 MultiMatchQuery ¶ added in v0.120.0
type MultiMatchQuery struct {
*types.MultiMatchQuery
}
func (*MultiMatchQuery) SetBoost ¶ added in v0.120.0
func (q *MultiMatchQuery) SetBoost(boost float32)
func (*MultiMatchQuery) SetFuzziness ¶ added in v0.120.0
func (q *MultiMatchQuery) SetFuzziness(fuzziness FuzzinessValue)
func (*MultiMatchQuery) SetFuzzyTranspositions ¶ added in v0.120.0
func (q *MultiMatchQuery) SetFuzzyTranspositions(value bool)
func (*MultiMatchQuery) SetName ¶ added in v0.120.0
func (q *MultiMatchQuery) SetName(name string)
func (*MultiMatchQuery) SetSlop ¶ added in v0.120.0
func (q *MultiMatchQuery) SetSlop(slop int)
func (*MultiMatchQuery) SetTextQueryType ¶ added in v0.120.0
func (q *MultiMatchQuery) SetTextQueryType(tq TextQueryType)
type Nameable ¶ added in v0.120.0
type Nameable interface {
*TermQuery | *TermsQuery | *ExistsQuery | *MatchAllQuery | *MatchQuery | *MatchPhraseQuery | *MultiMatchQuery | *WildcardQuery
SetName(name string)
}
Nameable represents a query option that can be named.
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 ¶
func Exists(field string, options ...func(*ExistsQuery)) Option
Exists query adds an "Exists" clause.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-exists-query
func Match ¶
func Match(field, value string, options ...func(*MatchQuery)) Option
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(options ...func(*MatchAllQuery)) Option
MatchAll adds a "Match All" clause.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html
func MatchPhrase ¶ added in v0.130.0
func MatchPhrase(field, value string, options ...func(*MatchPhraseQuery)) Option
MatchPhrase adds a "MatchPhrase" query on the given field with the given value.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-match-query-phrase
func MultiMatch ¶
func MultiMatch(value string, fields []string, options ...func(*MultiMatchQuery)) Option
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 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
func Terms ¶
func Terms[T any](field string, values []T, options ...func(*TermsQuery)) Option
Terms adds a "Terms" query on the given field with the given string value.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-terms-query
func Wildcard ¶ added in v0.128.0
func Wildcard(field string, value string, options ...func(*WildcardQuery)) Option
Wildcard adds a "Wildcard" query on the given field with the given value.
https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-wildcard-query
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.
type Sloppiness ¶ added in v0.120.0
type Sloppiness interface {
*MatchPhraseQuery | *MultiMatchQuery
SetSlop(slop int)
}
Sloppiness represents a query that can define a slop value.
type TermsQuery ¶ added in v0.120.0
type TermsQuery struct {
*types.TermsQuery
}
func (*TermsQuery) SetBoost ¶ added in v0.120.0
func (q *TermsQuery) SetBoost(boost float32)
func (*TermsQuery) SetName ¶ added in v0.120.0
func (q *TermsQuery) SetName(name string)
type TextQueryType ¶ added in v0.120.0
type TextQueryType = textquerytype.TextQueryType
type TextQueryTypes ¶ added in v0.120.0
type TextQueryTypes interface {
*MultiMatchQuery
SetTextQueryType(tq TextQueryType)
}
TextQueryTypes represents a query that has different text query operating modes.
type WildcardQuery ¶ added in v0.128.0
type WildcardQuery struct {
*types.WildcardQuery
}
func (*WildcardQuery) SetBoost ¶ added in v0.128.0
func (q *WildcardQuery) SetBoost(boost float32)
func (*WildcardQuery) SetName ¶ added in v0.128.0
func (q *WildcardQuery) SetName(name string)