query

package
v0.99.2 Latest Latest
Warning

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

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

Documentation

Overview

Package query contains methods for building Elasticsearch queries.

Index

Constants

View Source
const FuzzinessAuto = "AUTO"

Variables

This section is empty.

Functions

func Build

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

Build creates a query from the given options.

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

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 Match

func Match(field, fuzziness string, value string) 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, fuzziness string, fields ...string) 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 MultiMatchPrefix added in v0.28.1

func MultiMatchPrefix(value string, fields ...string) Option

MultiMatchPrefix adds a "MultiMatch" query on the given field with the given value and performing a phrase_prefix search.

https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-multi-match-query#type-phrase

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

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.

Jump to

Keyboard shortcuts

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