query

package
v0.128.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package query contains methods for building Elasticsearch queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(options ...Option) *types.Query

Build creates a query from the given options.

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

func WithFuzzyTranspositions[T Fuzziness](value bool) func(T)

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

func WithQueryBoost[T Boostable](boost float32) func(T)

WithQueryBoost applies a boost to this query option.

func WithQueryName added in v0.120.0

func WithQueryName[T Nameable](name string) func(T)

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

type BoolOption func(*types.BoolQuery)

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.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#named-queries

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.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#named-queries

type Boostable added in v0.120.0

type Boostable interface {
	*TermQuery | *TermsQuery | *ExistsQuery | *MatchAllQuery | *MatchQuery | *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 FuzzinessValue types.Fuzziness

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 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 | *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

type Option func(*types.Query)

Option is a functional option for queries.

func Before added in v0.40.0

func Before(field string, before time.Time) Option

Before adds a "Range" query to find documents older than the given time.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#ranges-on-dates

func Between

func Between(field string, from time.Time, to time.Time) Option

Between adds a "Range" query to find documents between (or equal to) the given times.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#ranges-on-dates

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

func Distance(field, pivot, origin string) Option

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 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

func SearchAsYouType(text string, field string) Option

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 Since

func Since(field string, since time.Time) Option

Since adds a "Range" query to find documents newer than the given time.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#ranges-on-dates

func Term

func Term(field string, value any, options ...func(*TermQuery)) Option

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 {
	*MultiMatchQuery

	SetSlop(slop int)
}

Sloppiness represents a query that can define a slop value.

type TermQuery added in v0.120.0

type TermQuery struct {
	*types.TermQuery
}

func (*TermQuery) SetBoost added in v0.120.0

func (q *TermQuery) SetBoost(boost float32)

func (*TermQuery) SetName added in v0.120.0

func (q *TermQuery) SetName(name string)

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)

Jump to

Keyboard shortcuts

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