Documentation ¶
Overview ¶
Package search contains types for constructing queries in Elasticsearch
Index ¶
- Variables
- func NewIndicesBoost() map[string]float32
- type AnalyzerParam
- type AutoGenerateSynonymsPhraseQueryParam
- type BoostParam
- type Builder
- type CaseInsensitiveParam
- type DocValueFields
- type Exists
- type Field
- type Fields
- type FuzzinessParam
- type Fuzzy
- type FuzzyQuery
- type FuzzyTranspositionsParam
- type IDsQuery
- type IndicesBoost
- type LenientParam
- type Match
- type MatchBooleanPrefix
- type MatchBooleanPrefixQuery
- type MatchPhrase
- type MatchPhrasePrefix
- type MatchPhrasePrefixQuery
- type MatchPhraseQuery
- type MatchQuery
- type MatchQueryValue
- type MaxExpansionsParam
- type MinimumShouldMatchParam
- type Operator
- type OperatorParam
- type PointInTime
- type Prefix
- type PrefixLengthParam
- type PrefixQuery
- type PrefixQueryValue
- type Query
- type QueryError
- type QueryType
- type QueryWithCaseInsensitive
- type Rewrite
- type RewriteParam
- type RuntimeMappingField
- type RuntimeMappingType
- type RuntimeMappings
- type Search
- func (s *Search) AddMatch(field string, match Match) *Search
- func (s *Search) Clone() *Search
- func (s Search) DocValueFields() DocValueFields
- func (s Search) Explain() bool
- func (s Search) Fields() Fields
- func (s Search) From() int
- func (s Search) IndicesBoost() IndicesBoost
- func (s Search) MinScore() float32
- func (s Search) PIT() *PointInTime
- func (s Search) PointInTime() *PointInTime
- func (s Search) Query() *Query
- func (s Search) RuntimeMappings() RuntimeMappings
- func (s Search) SeqNoPrimaryTerm() bool
- func (s *Search) SetDocValueFields(v DocValueFields) *Search
- func (s *Search) SetExplain(v bool) *Search
- func (s *Search) SetFields(v Fields) *Search
- func (s *Search) SetFrom(v int) *Search
- func (s *Search) SetIndicesBoost(v IndicesBoost) *Search
- func (s *Search) SetMatch(field string, match Match) *Search
- func (s *Search) SetMinScore(v float32) *Search
- func (s *Search) SetPIT(v *PointInTime) *Search
- func (s *Search) SetPointInTime(v *PointInTime) *Search
- func (s *Search) SetQuery(v *Query) *Search
- func (s *Search) SetRuntimeMappings(v RuntimeMappings) *Search
- func (s *Search) SetSeqNoPrimaryTerm(v bool) *Search
- func (s *Search) SetSize(v int) *Search
- func (s *Search) SetSource(v interface{}) *Search
- func (s *Search) SetStats(v []string) *Search
- func (s *Search) SetTerminateAfter(v int) *Search
- func (s *Search) SetTimeout(v time.Duration) *Search
- func (s *Search) SetVersion(v bool) *Search
- func (s Search) Size() int
- func (s Search) Source() *Source
- func (s Search) Stats() []string
- func (s Search) TerminateAfter() int
- func (s Search) Timeout() time.Duration
- func (s Search) Version() bool
- type SlopParam
- type Source
- type SourceSpecifications
- type Term
- type TermQuery
- type TranspositionsParam
- type WithAnalyzer
- type WithAutoGenerateSynonymsPhraseQuery
- type WithBoost
- type WithFuzziness
- type WithFuzzyTranspositions
- type WithLenient
- type WithMaxExpansions
- type WithMinimumShouldMatch
- type WithOperator
- type WithPrefixLength
- type WithRewrite
- type WithSlop
- type WithTranspositions
- type WithZeroTermsQuery
- type ZeroTermsQuery
- type ZeroTermsQueryParam
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingValue = errors.New("error: value is required") ErrMissingQuery = errors.New("error: query is required") ErrInvalidSourceType = errors.New("error: invalid source type") ErrInvalidRewrite = errors.New("error: invalid rewrite value") ErrFieldExists = errors.New("error: field exists") )
var DefaultBuilder = Builder{}
Functions ¶
func NewIndicesBoost ¶
Types ¶
type AnalyzerParam ¶
type AnalyzerParam struct {
AnalyzerValue string `json:"analyzer,omitempty" bson:"analyzer,omitempty"`
}
AnalyzerParam is a query mixin that adds the analyzer param
Analyzer used to convert the text in the query value into tokens. Defaults to the index-time analyzer mapped for the <field>. If no analyzer is mapped, the index’s default analyzer is used. (Optional)
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html
func (AnalyzerParam) Analyzer ¶
func (a AnalyzerParam) Analyzer() string
Analyzer used to convert the text in the query value into tokens. Defaults to the index-time analyzer mapped for the <field>. If no analyzer is mapped, the index’s default analyzer is used. (Optional)
func (*AnalyzerParam) SetAnalyzer ¶
func (a *AnalyzerParam) SetAnalyzer(v string)
SetAnalyzer sets the Analyzer value to v
type AutoGenerateSynonymsPhraseQueryParam ¶
type AutoGenerateSynonymsPhraseQueryParam struct {
AutoGenerateSynonymsPhraseQueryValue *bool `bson:"auto_generate_synonyms_phrase_query,omitempty" json:"auto_generate_synonyms_phrase_query,omitempty"`
}
func (AutoGenerateSynonymsPhraseQueryParam) AutoGenerateSynonymsPhraseQuery ¶
func (agspq AutoGenerateSynonymsPhraseQueryParam) AutoGenerateSynonymsPhraseQuery() bool
AutoGenerateSynonymsPhraseQuery determines if match phrase queries are automatically created for multi-term synonyms. Defaults to true.
func (*AutoGenerateSynonymsPhraseQueryParam) SetAutoGenerateSynonymsPhraseQuery ¶
func (agspq *AutoGenerateSynonymsPhraseQueryParam) SetAutoGenerateSynonymsPhraseQuery(v bool)
SetAutoGenerateSynonymsPhraseQuery sets AutoGenerateSynonymsPhraseQueryValue to v
type BoostParam ¶
type BoostParam struct {
BoostValue *float32 `bson:"boost,omitempty" json:"boost,omitempty"`
}
func (BoostParam) Boost ¶
func (b BoostParam) Boost() float32
func (*BoostParam) SetBoost ¶
func (b *BoostParam) SetBoost(v float32)
type CaseInsensitiveParam ¶
type CaseInsensitiveParam struct {
CaseInsensitiveValue *bool `json:"case_insensitive,omitempty" bson:"case_insensitive,omitempty"`
}
CaseInsensitiveParam is a query mixin that adds the case_insensitive param
(Optional, Boolean) Allows ASCII case insensitive matching of the value with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
func (CaseInsensitiveParam) CaseInsensitive ¶
func (ci CaseInsensitiveParam) CaseInsensitive() bool
func (CaseInsensitiveParam) Default ¶
func (ci CaseInsensitiveParam) Default() bool
func (*CaseInsensitiveParam) SetCaseInsensitive ¶
func (ci *CaseInsensitiveParam) SetCaseInsensitive(v bool)
type DocValueFields ¶
type DocValueFields Fields
DocValueFields is used to return doc values for one or more fields in the search response.
(Optional, array of strings and objects) Array of wildcard (*) patterns. The request returns doc values for field names matching these patterns in the hits.fields property of the response. You can use the docvalue_fields parameter to return doc values for one or more fields in the search response.
Doc values store the same values as the _source but in an on-disk, column-based structure that’s optimized for sorting and aggregations. Since each field is stored separately, Elasticsearch only reads the field values that were requested and can avoid loading the whole document _source.
Doc values are stored for supported fields by default. However, doc values are not supported for text or text_annotated fields.
The following search request uses the docvalue_fields parameter to retrieve doc values for the user.id field, all fields starting with http.response., and the @timestamp field:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#docvalue-fields
See also:
https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html
func (DocValueFields) Clone ¶
func (f DocValueFields) Clone() DocValueFields
type Exists ¶
type Exists struct {
Field string `json:"field" bson:"field"`
}
Exists returns documents that contain an indexed value for a field.
An indexed value may not exist for a document’s field due to a variety of reasons:
- The field in the source JSON is null or []
- The field has "index" : false set in the mapping
- The length of the field value exceeded an ignore_above setting in the mapping
- The field value was malformed and ignore_malformed was defined in the mapping
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
type Field ¶
type Field struct { // (Required, string) Wildcard pattern. The request returns doc values for // field names matching this pattern. Field string `bson:"field" json:"field"` // (Optional, string) Format in which the doc values are returned. // // For date fields, you can specify a date date format. For numeric fields // fields, you can specify a DecimalFormat pattern. // // For other field data types, this parameter is not supported. Format string `bson:"format,omitempty" json:"format,omitempty"` }
func (Field) MarshalJSON ¶
func (*Field) UnmarshalJSON ¶
type Fields ¶
type Fields []Field
Fields allows for retrieving a list of document fields in the search response. It consults both the document _source and the index mappings to return each value in a standardized way that matches its mapping type. By default, date fields are formatted according to the date format parameter in their mappings. You can also use the fields parameter to retrieve runtime field values.
(Optional, array of strings and objects) Array of wildcard (*) patterns. The request returns values for field names matching these patterns in the hits.fields property of the response.
You can specify items in the array as a string or object. See Fields for more details.
type FuzzinessParam ¶
type FuzzinessParam struct { FuzzinessValue string `json:"fuzziness,omitempty" bson:"fuzziness,omitempty"` FuzzyRewriteValue Rewrite `json:"fuzzy_rewrite,omitempty" bson:"fuzzy_rewrite,omitempty"` }
FuzzinessParam is a mixin that adds the fuzziness parameter to queries
Maximum edit distance allowed for matching. See Fuzziness for valid values and more information.
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness
func (FuzzinessParam) Fuzziness ¶
func (f FuzzinessParam) Fuzziness() string
Fuzziness is the maximum edit distance allowed for matching. See Fuzziness for valid values and more information.
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness
func (FuzzinessParam) FuzzyRewrite ¶
func (f FuzzinessParam) FuzzyRewrite() Rewrite
FuzzyRewrite is the method used to rewrite the query. See the rewrite parameter for valid values and more information.
If the fuzziness parameter is not 0, the match query uses a fuzzy_rewrite method of top_terms_blended_freqs_${max_expansions} by default.
func (*FuzzinessParam) SetFuzziness ¶
func (f *FuzzinessParam) SetFuzziness(v string)
SetFuzziness sets the fuzzinessValue to v
func (*FuzzinessParam) SetFuzzyRewrite ¶
func (f *FuzzinessParam) SetFuzzyRewrite(v Rewrite) error
SetFuzzyRewrite sets the value of FuzzyRewrite to v
type Fuzzy ¶
type Fuzzy struct { Value string `json:"value" bson:"value"` FuzzinessParam `json:",inline" bson:",inline"` MaxExpansionsParam `json:",inline" bson:",inline"` PrefixLengthParam `json:",inline" bson:",inline"` TranspositionsParam `json:",inline" bson:",inline"` RewriteParam `json:",inline" bson:",inline"` }
Fuzzy returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance.
An edit distance is the number of one-character changes needed to turn one term into another. These changes can include:
- Changing a character (box → fox)
- Removing a character (black → lack)
- Inserting a character (sic → sick)
- Transposing two adjacent characters (act → cat)
To find similar terms, the fuzzy query creates a set of all possible variations, or expansions, of the search term within a specified edit distance. The query then returns exact matches for each expansion.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
type FuzzyQuery ¶
FuzzyQuery returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance.
An edit distance is the number of one-character changes needed to turn one term into another. These changes can include:
- Changing a character (box → fox)
- Removing a character (black → lack)
- Inserting a character (sic → sick)
- Transposing two adjacent characters (act → cat)
To find similar terms, the fuzzy query creates a set of all possible variations, or expansions, of the search term within a specified edit distance. The query then returns exact matches for each expansion.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
func NewFuzzyQuery ¶
func NewFuzzyQuery() FuzzyQuery
type FuzzyTranspositionsParam ¶
type FuzzyTranspositionsParam struct {
FuzzyTranspositionsValue *bool `json:"fuzzy_transpositions,omitempty" bson:"fuzzy_transpositions,omitempty"`
}
func (FuzzyTranspositionsParam) FuzzyTranspositions ¶
func (ft FuzzyTranspositionsParam) FuzzyTranspositions() bool
FuzzyTranspositions edits for fuzzy matching include transpositions of two adjacent characters (ab → ba). Defaults to true
func (*FuzzyTranspositionsParam) SetFuzzyTranspositions ¶
func (ft *FuzzyTranspositionsParam) SetFuzzyTranspositions(v bool)
SetFuzzyTranspositions sets FuzzyTranspositions to v
type IndicesBoost ¶
IndicesBoost boosts the _score of documents from specified indices
func (IndicesBoost) Clone ¶
func (ib IndicesBoost) Clone() IndicesBoost
type LenientParam ¶
type LenientParam struct {
LenientValue *bool `json:"lenient,omitempty" bson:"lenient,omitempty"`
}
LenientParam is a query mixin that adds the lenient para
if true, format-based errors, such as providing a text query value for a numeric field, are ignored. Defaults to false.
func (LenientParam) Lenient ¶
func (l LenientParam) Lenient() bool
Lenient determines whether format-based errors, such as providing a text query value for a numeric field, are ignored. Defaults to false.
func (*LenientParam) SetLenient ¶
func (l *LenientParam) SetLenient(v bool)
SetLenient sets Lenient to v
type Match ¶
type Match struct { Query interface{} Analyzer string NoAutoGenerateSynonymsPhraseQuery bool NoFuzzyTranspositions bool Fuzziness string FuzzyRewrite Rewrite Lenient bool Operator Operator MaxExpansions int PrefixLength int MinimumShouldMatchParam string ZeroTermsQuery ZeroTermsQuery }
Match returns documents that match a provided text, number, date or boolean value. The provided text is analyzed before matching.
The match query is the standard query for performing a full-text search, including options for fuzzy matching.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
func (Match) QueryValue ¶
func (m Match) QueryValue() (MatchQueryValue, error)
type MatchBooleanPrefix ¶
type MatchBooleanPrefix struct { Query string `json:"query" bson:"query"` MinimumShouldMatchParam `json:",inline" bson:",inline"` OperatorParam `json:",inline" bson:",inline"` AnalyzerParam `json:",inline" bson:",inline"` FuzzinessParam `json:",inline" bson:",inline"` PrefixLengthParam `json:",inline" bson:",inline"` FuzzyTranspositionsParam `json:",inline" bson:",inline"` }
type MatchBooleanPrefixQuery ¶
type MatchBooleanPrefixQuery struct {
MatchBooleanPrefix map[string]MatchBooleanPrefix `json:"match_boolean_prefix,omitempty" bson:"match_boolean_prefix,omitempty"`
}
func NewMatchBooleanPrefixQuery ¶
func NewMatchBooleanPrefixQuery() MatchBooleanPrefixQuery
type MatchPhrase ¶
type MatchPhrase struct { Query string `json:"query" bson:"query"` AnalyzerParam `json:",inline" bson:",inline"` ZeroTermsQueryParam `json:",inline" bson:",inline"` }
type MatchPhrasePrefix ¶
type MatchPhrasePrefix struct { Query string `json:"query" bson:"query"` AnalyzerParam `json:",inline" bson:",inline"` MaxExpansionsParam `json:",inline" bson:",inline"` SlopParam `json:",inline" bson:",inline"` ZeroTermsQuery `json:",inline" bson:",inline"` }
func NewMatchPhrasePrefix ¶
func NewMatchPhrasePrefix(query string) MatchPhrasePrefix
type MatchPhrasePrefixQuery ¶
type MatchPhrasePrefixQuery struct {
MatchPhrasePrefix map[string]MatchBooleanPrefix `json:"match_phrase_prefix,omitempty" bson:"match_phrase_prefix,omitempty"`
}
type MatchPhraseQuery ¶
type MatchPhraseQuery struct {
MatchPhrase map[string]MatchPhrase `json:"match_phrase,omitempty" bson:"match_phrase,omitempty"`
}
func (*MatchPhraseQuery) SetMatchPhrase ¶
func (mp *MatchPhraseQuery) SetMatchPhrase(field string, matchPhrase MatchPhrase)
type MatchQuery ¶
type MatchQuery struct {
MatchQueryValue map[string]MatchQueryValue `json:"match,omitempty" bson:"match,omitempty"`
}
MatchQuery returns documents that match a provided text, number, date or boolean value. The provided text is analyzed before matching.
The match query is the standard query for performing a full-text search, including options for fuzzy matching.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
func NewMatchQuery ¶
func NewMatchQuery() MatchQuery
func (*MatchQuery) AddMatch ¶
func (m *MatchQuery) AddMatch(field string, match Match) error
AddMatch returns an error if the field already exists. Use SetMatch to overwrite.
func (*MatchQuery) RemoveMatch ¶
func (m *MatchQuery) RemoveMatch(field string)
type MatchQueryValue ¶
type MatchQueryValue struct { // (Required) Text, number, boolean value or date you wish to find in the // provided <field>. // // The match query analyzes any provided text before performing a search. // This means the match query can search text fields for analyzed tokens // rather than an exact term. Query dynamic.StringNumberBoolOrTime `json:"query" bson:"query"` // Analyzer used to convert the text in the query value into tokens. // Defaults to the index-time analyzer mapped for the <field>. If no // analyzer is mapped, the index’s default analyzer is used. AnalyzerParam `json:",inline" bson:",inline"` // If true, match phrase queries are automatically created for multi-term // synonyms. Defaults to true. AutoGenerateSynonymsPhraseQueryParam `json:",inline" bson:",inline"` // Maximum edit distance allowed for matching. FuzzinessParam `json:",inline" bson:",inline"` // Maximum number of terms to which the query will expand. Defaults to 50. MaxExpansionsParam `json:",inline" bson:",inline"` // Number of beginning characters left unchanged for fuzzy matching. Defaults to 0. PrefixLengthParam `json:",inline" bson:",inline"` // If true, edits for fuzzy matching include transpositions of two adjacent // characters (ab → ba). Defaults to true. FuzzyTranspositionsParam `json:",inline" bson:",inline"` // If true, format-based errors, such as providing a text query value for a // numeric field, are ignored. Defaults to false. LenientParam `json:",inline" bson:",inline"` // Boolean logic used to interpret text in the query value. OperatorParam `json:",inline" bson:",inline"` // Minimum number of clauses that must match for a document to be returned // // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html MinimumShouldMatchParam `json:",inline" bson:",inline"` // Indicates whether no documents are returned if the analyzer removes all // tokens, such as when using a stop filter. ZeroTermsQueryParam `json:",inline" bson:",inline"` }
MatchQueryValue returns documents that match a provided text, number, date or boolean value. The provided text is analyzed before matching.
The match query is the standard query for performing a full-text search, including options for fuzzy matching.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
func (*MatchQueryValue) SetQuery ¶
func (mq *MatchQueryValue) SetQuery(value interface{}) error
type MaxExpansionsParam ¶
type MaxExpansionsParam struct {
MaxExpansionsValue *int `json:"max_expansions,omitempty" bson:"max_expansions,omitempty"`
}
MaxExpansionsParam is a mixin that adds the max_expansions param to queries
Maximum number of variations created. Defaults to 50.
WARNING ¶
Avoid using a high value in the max_expansions parameter, especially if the prefix_length parameter value is 0. High values in the max_expansions parameter can cause poor performance due to the high number of variations examined.
func (MaxExpansionsParam) MaxExpansions ¶
func (me MaxExpansionsParam) MaxExpansions() int
MaxExpansions is the maximum number of variations created. Defaults to 50.
func (*MaxExpansionsParam) SetMaxExpansions ¶
func (me *MaxExpansionsParam) SetMaxExpansions(v int)
type MinimumShouldMatchParam ¶
type MinimumShouldMatchParam struct {
MimimumShouldMatchValue *string `json:"minimum_should_match,omitempty" bson:"minimum_should_match,omitempty"`
}
func (MinimumShouldMatchParam) MinimumShouldMatch ¶
func (msm MinimumShouldMatchParam) MinimumShouldMatch() string
func (*MinimumShouldMatchParam) SetMinimumShouldMatch ¶
func (msm *MinimumShouldMatchParam) SetMinimumShouldMatch(v string)
type OperatorParam ¶
type OperatorParam struct {
OperatorValue *Operator `json:"operator,omitempty" bson:"operator,omitempty"`
}
OperatorParam is a query mixin that adds the operator param
func (OperatorParam) Operator ¶
func (o OperatorParam) Operator() Operator
Operator is the boolean logic used to interpret text in the query value. Defaults to Or
func (*OperatorParam) SetOperator ¶
func (o *OperatorParam) SetOperator(v Operator)
SetOperator sets the Operator to v
type PointInTime ¶
type PointInTime struct { ID string `bson:"id" json:"id"` KeepAlive *time.Time `bson:"keep_alive,omitempty" json:"keep_alive,omitempty"` }
PointInTime is a lightweight view into the state of the data as it existed when initiated.
! X-Pack
A search request by default executes against the most recent visible data of the target indices, which is called point in time. Elasticsearch pit (point in time) is a lightweight view into the state of the data as it existed when initiated. In some cases, it’s preferred to perform multiple search requests using the same point in time. For example, if refreshes happen between search_after requests, then the results of those requests might not be consistent as changes happening between searches are only visible to the more recent point in time.
Prerequisites ¶
- If the Elasticsearch security features are enabled, you must have the read index privilege for the target data stream, index, or index alias.
- To search a point in time (PIT) for an index alias, you must have the read index privilege for the alias’s concrete indices.
https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html
func (*PointInTime) Clone ¶
func (pit *PointInTime) Clone() *PointInTime
type PrefixLengthParam ¶
type PrefixLengthParam struct {
PrefixLengthValue *int `json:"prefix_length,omitempty" bson:"prefix_length,omitempty"`
}
func (PrefixLengthParam) PrefixLength ¶
func (pl PrefixLengthParam) PrefixLength() int
func (*PrefixLengthParam) SetPrefixLength ¶
func (pl *PrefixLengthParam) SetPrefixLength(v int)
type PrefixQuery ¶
type PrefixQuery struct {
PrefixQueryValue `json:"prefix,omitempty" bson:"prefix,omitempty"`
}
PrefixQuery returns documents that contain a specific prefix in a provided field.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html
func (*PrefixQuery) Prefix ¶
func (p *PrefixQuery) Prefix(v Prefix)
Prefix returns documents that contain a specific prefix in a provided field.
Prefix panics if Value is not set. It is intended to be used inside of a builder.
type PrefixQueryValue ¶
type PrefixQueryValue struct { Value string `json:"value" bson:"value"` RewriteParam `json:",inline" bson:",inline"` CaseInsensitiveParam `json:",inline" bson:",inline"` }
PrefixQueryValue returns documents that contain a specific prefix in a provided field.
type Query ¶
type Query struct {
MatchQuery `json:",inline" bson:",inline"`
}
Query defines the search definition using the ElasticSearch Query DSL
Elasticsearch provides a full Query DSL (Domain Specific Language) based on JSON to define queries. Think of the Query DSL as an AST (Abstract Syntax Tree) of queries, consisting of two types of clauses:
Leaf query clauses ¶
Leaf query clauses look for a particular value in a particular field, such as the match, term or range queries. These queries can be used by themselves.
Compound query clauses ¶
Compound query clauses wrap other leaf or compound queries and are used to combine multiple queries in a logical fashion (such as the bool or dis_max query), or to alter their behaviour (such as the constant_score query).
Query clauses behave differently depending on whether they are used in query context or filter context.
type QueryError ¶
func NewQueryError ¶
func NewQueryError(err error, queryType QueryType) *QueryError
func (QueryError) Error ¶
func (s QueryError) Error() string
func (QueryError) Unwrap ¶
func (s QueryError) Unwrap() error
type QueryWithCaseInsensitive ¶
QueryWithCaseInsensitive is a query mixin that adds the case_insensitive param
(Optional, Boolean) Allows ASCII case insensitive matching of the value with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
type Rewrite ¶
type Rewrite string
Rewrite as defined by:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-term-rewrite.html
const ( // RewriteTypeConstantScore uses the constant_score_boolean method for fewer matching // terms. Otherwise, this method finds all matching terms in sequence and // returns matching documents using a bit set. RewriteConstantScore Rewrite = "constant_score" // RewriteTypeConstantScoreBoolean assigns each document a relevance score equal to the // boost parameter. // // This method changes the original query to a bool query. This bool query // contains a should clause and term query for each matching term. // // This method can cause the final bool query to exceed the clause limit in the // indices.query.bool.max_clause_count setting. If the query exceeds this limit, // Elasticsearch returns an error. RewriteConstantScoreBoolean Rewrite = "constant_score_boolean" // RewriteTypeScoringBoolean calculates a relevance score for each matching document. // // This method changes the original query to a bool query. This bool query // contains a should clause and term query for each matching term. // // This method can cause the final bool query to exceed the clause limit in the // indices.query.bool.max_clause_count setting. If the query exceeds this limit, // Elasticsearch returns an error. RewriteScoringBoolean Rewrite = "scoring_boolean" // RewriteTypeTopTermsBlendedFreqsN calculates a relevance score for each // matching document as if all terms had the same frequency. This frequency // is the maximum frequency of all matching terms. // // This method changes the original query to a bool query. This bool query // contains a should clause and term query for each matching term. // // The final bool query only includes term queries for the top N scoring // terms. // // You can use this method to avoid exceeding the clause limit in the // indices.query.bool.max_clause_count setting. // RewriteTopTermsBlendedFreqsN Rewrite = "top_terms_blended_freqs_N" // RewriteTypeTopTermsBoostN Assigns each matching document a relevance // score equal to the boost parameter. // // This method changes the original query to a bool query. This bool query // contains a should clause and term query for each matching term. // // The final bool query only includes term queries for the top N terms. // // You can use this method to avoid exceeding the clause limit in the // indices.query.bool.max_clause_count setting. RewriteTopTermsBoostN Rewrite = "top_terms_boost_N" // RewriteTopTermsN calculates a relevance score for each matching document. // // This method changes the original query to a bool query. This bool query // contains a should clause and term query for each matching term. // // The final bool query only includes term queries for the top N scoring terms. // // You can use this method to avoid exceeding the clause limit in the // indices.query.bool.max_clause_count setting. RewriteTopTermsN Rewrite = "top_terms_N" )
type RewriteParam ¶
type RewriteParam struct {
RewriteValue *Rewrite `json:"rewrite,omitempty" bson:"rewrite,omitempty"`
}
RewriteParam is a mixin that adds the rewrite param
Method used to rewrite the query. For valid values and more information, see the rewrite parameter. (Optional)
func (RewriteParam) Default ¶
func (r RewriteParam) Default() Rewrite
func (RewriteParam) Rewrite ¶
func (r RewriteParam) Rewrite() Rewrite
func (*RewriteParam) SetRewrite ¶
func (r *RewriteParam) SetRewrite(v Rewrite)
type RuntimeMappingField ¶
type RuntimeMappingField struct { Type RuntimeMappingType `bson:"type" json:"type"` Script string `bson:"script,omitempty" json:"script,omitempty"` }
type RuntimeMappingType ¶
type RuntimeMappingType string
const ( RMTBoolean RuntimeMappingType = "boolean" RMTDate RuntimeMappingType = "date" RMTDouble RuntimeMappingType = "double" RMTGeoPoint RuntimeMappingType = "geo_point" RMTIP RuntimeMappingType = "ip" RMTKeyword RuntimeMappingType = "keyword" RMTLong RuntimeMappingType = "long" )
type RuntimeMappings ¶
type RuntimeMappings map[string]RuntimeMappingField
func (RuntimeMappings) Clone ¶
func (rtm RuntimeMappings) Clone() RuntimeMappings
type Search ¶
type Search struct { // Array of wildcard (*) patterns. The request returns doc values for field // names matching these patterns in the hits.fields property of the response // (Optional) . // // You can specify items in the array as a string or object. DocValueFieldsValue DocValueFields `bson:"docvalue_fields,omitempty" json:"docvalue_fields,omitempty"` // Array of wildcard (*) patterns. The request returns values for field // names matching these patterns in the hits.fields property of the response // (Optional). // // You can specify items in the array as a string or object. FieldsValue Fields `bson:"fields,omitempty" json:"fields,omitempty"` // (Optional, Boolean) If true, returns detailed information about score // computation as part of a hit. Defaults to false. ExplainValue *bool `bson:"epxlain,omitempty" json:"explain,omitempty"` // Starting document offset. Defaults to 0. // // By default, you cannot page through more than 10,000 hits using the from // and size parameters. To page through more hits, use the search_after // parameter. FromValue *int `bson:"from,omitempty" json:"from,omitempty"` // Boosts the _score of documents from specified indices (Optional). IndicesBoostValue IndicesBoost `bson:"indices_boost,omitempty"` // Minimum _score for matching documents. Documents with a lower _score are // not included in the search results (Optional, float). MinScoreValue *float32 `bson:"min_score,omitempty" json:"min_score,omitempty"` // Limits the search to a point in time (PIT). If you provide a pit, you // cannot specify a <target> in the request path. (Optional) PointInTimeValue *PointInTime `bson:"pit,omitempty" json:"pit,omitempty"` // Defines the search definition using the Query DSL. (Optional) QueryValue *Query `bson:"query,omitempty" json:"query,omitempty"` // Defines a runtime field in the search request that exist only as part of // the query. Fields defined in the search request take precedence over // fields defined with the same name in the index mappings. (Optional) RuntimeMappingsValue RuntimeMappings `bson:"runtime_mappings,omitempty" json:"runtime_mappings,omitempty"` // If true, returns sequence number and primary term of the last // modification of each hit. See Optimistic concurrency control. (Optional) SeqNoPrimaryTermValue *bool `bson:"seq_no_primary_term,omitempty" json:"seq_no_primary_term,omitempty"` // The number of hits to return. Defaults to 10. (Optional) // // By default, you cannot page through more than 10,000 hits using the from and size parameters. To page through more hits, use the search_after parameter. SizeValue *int `bson:"size,omitempty" json:"size,omitempty"` // Indicates which source fields are returned for matching documents. These fields are returned in the hits._source property of the search response. Defaults to true. (Optional) SourceValue *Source `bson:"_source,omitempty" json:"_source,omitempty"` // Stats groups to associate with the search. Each group maintains a statistics aggregation for its associated searches. You can retrieve these stats using the indices stats API (Optional). StatsValue []string `bson:"stats,omitempty" json:"stats,omitempty"` TerminateAfterValue *int `bson:"terminate_after,omitempty" json:"terminate_after,omitempty"` TimeoutValue *time.Duration `bson:"timeout,omitempty" json:"timeout,omitempty"` VersionValue *bool `bson:"version,omitempty" json:"version,omitempty"` }
func (*Search) AddMatch ¶
AddMatch adds a match query to the search. It panics if the field already exists or other errors arise (like not setting the query). Use SetMatch to overwrite the field instead.
AddMatch panics if there is an error. It is intended to be utilized in a builder. To avoid panics, use the same function on the Query itself:
s := search.NewSearch() s.AddMatch("field", Match{Query: "example"}) s.AddMatch("field", Match{Query: "example"}) // This will panic // this will not: err := s.Query().AddMatch(field, match) _ = err // handle error
func (Search) DocValueFields ¶
func (s Search) DocValueFields() DocValueFields
DocValueFields is used to return return doc values for one or more fields in the search response.
(Optional, array of strings and objects) Array of wildcard (*) patterns. The request returns doc values for field names matching these patterns in the hits.fields property of the response.
You can specify items in the array as a string or object.
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#docvalue-fields
func (Search) Explain ¶
Explain indicates whether the search returns detailed information about score computation as part of a hit. Defaults to false.
func (Search) Fields ¶
Fields allows for retrieving a list of document fields in the search response. It consults both the document _source and the index mappings to return each value in a standardized way that matches its mapping type. By default, date fields are formatted according to the date format parameter in their mappings. You can also use the fields parameter to retrieve runtime field values.
func (Search) From ¶
From sets the starting document offset. Defaults to 0.
By default, you cannot page through more than 10,000 hits using the from and size parameters. To page through more hits, use the search_after parameter.
func (Search) IndicesBoost ¶
func (s Search) IndicesBoost() IndicesBoost
IndicesBoost buusts the _score of documents from specified indices
func (Search) MinScore ¶
MinScore is the minimum _score for matching documents. Documents with a lower _score are not included in the search results.
func (Search) PointInTime ¶
func (s Search) PointInTime() *PointInTime
PointInTime is a lightweight view into the state of the data as it existed when initiated
https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html
func (Search) Query ¶
Query defines the search definition using the Query DSL.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
func (Search) RuntimeMappings ¶
func (s Search) RuntimeMappings() RuntimeMappings
func (Search) SeqNoPrimaryTerm ¶
SeqNoPrimaryTerm https://www.elastic.co/guide/en/elasticsearch/reference/current/optimistic-concurrency-control.html
func (*Search) SetDocValueFields ¶
func (s *Search) SetDocValueFields(v DocValueFields) *Search
SetDocValueFields sets DocValueFieldsValue to v
func (*Search) SetExplain ¶
SetExplain sets the ExplainValue to v
func (*Search) SetIndicesBoost ¶
func (s *Search) SetIndicesBoost(v IndicesBoost) *Search
SetIndicesBoost sets IndicesBoostValue to v
func (*Search) SetMatch ¶
SetMatch assigns a match query to the search. It overwrites the field if it exists. AddMatch will error instead
SetMatch panics if there is an error. It is intended to be utilized in a builder. To avoid panics, use the same function on the Query itself:
s := search.NewSearch() err := s.Query().SetMatch(field, match) _ = err // handle error
func (*Search) SetMinScore ¶
SetMinScore sets the MinScoreValue to v
func (*Search) SetPIT ¶
func (s *Search) SetPIT(v *PointInTime) *Search
SetPIT is an alias for SetPointInTime
func (*Search) SetPointInTime ¶
func (s *Search) SetPointInTime(v *PointInTime) *Search
SetPointInTime sets the PointInTimeValue to v
func (*Search) SetRuntimeMappings ¶
func (s *Search) SetRuntimeMappings(v RuntimeMappings) *Search
func (*Search) SetSeqNoPrimaryTerm ¶
func (*Search) SetSource ¶
SetSource sets the value of Source
The options are:
search.Source *search.Source string []string dynamic.StringOrArrayOfStrings *dynamic.StringOrArrayOfStrings search.SourceSpecifications *search.SourceSpecifications bool *bool nil
Note, "true" || "false" get parsed as boolean
SetSource panics if v is not one of the types listed above. The expectation is that this method will be utilized in a Builder
You can explicitly set the source, such as:
s := NewSearch() src := &Source{} err := src.SetValue(v) _ = err // handle err s.SourceValue = src
func (*Search) SetTerminateAfter ¶
func (*Search) SetVersion ¶
func (Search) Size ¶
Size is number of hits to return. Defaults to 10.
By default, you cannot page through more than 10,000 hits using the from and size parameters. To page through more hits, use the search_after parameter.
func (Search) Source ¶
Source indicates which source fields are returned for matching documents. These fields are returned in the hits._source property of the search response. Defaults to true.
func (Search) Stats ¶
Stats groups to associate with the search. Each group maintains a statistics aggregation for its associated searches. You can retrieve these stats using the indices stats API (Optional).
func (Search) TerminateAfter ¶
TerminateAfter is maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.
Defaults to 0, which does not terminate query execution early.
type SlopParam ¶
type SlopParam struct {
SlopValue *int `json:"slop,omitempty" bson:"slop,omitempty"`
}
type Source ¶
type Source struct { BoolValue *bool `bson:"bool,omitempty" json:"-"` WildcardPattern dynamic.StringOrArrayOfStrings `bson:"wildcard,omitempty" json:"-"` Specifications *SourceSpecifications }
type SourceSpecifications ¶
type SourceSpecifications struct { Includes dynamic.StringOrArrayOfStrings `bson:"includes,omitempty" json:"includes,omitempty"` Excludes dynamic.StringOrArrayOfStrings `bson:"excludes,omitempty" json:"excludes,omitempty"` }
type Term ¶
type Term struct { // Term you wish to find in the provided <field>. To return a document, the // term must exactly match the field value, including whitespace and // capitalization. (Required) Value string `json:"value" bson:"value"` BoostParam `json:",inline" bson:",inline"` CaseInsensitiveParam `json:",inline" bson:",inline"` }
Term query returns documents that contain an exact term in a provided field.
You can use the term query to find documents based on a precise value such as a price, a product ID, or a username.
Avoid using the term query for text fields.
By default, Elasticsearch changes the values of text fields as part of analysis. This can make finding exact matches for text field values difficult.
To search text field values, use the match query instead.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
func (Term) MarshalJSON ¶
func (*Term) UnmarshalJSON ¶
type TermQuery ¶
TermQuery returns documents that contain an exact term in a provided field.
You can use the term query to find documents based on a precise value such as a price, a product ID, or a username.
Avoid using the term query for text fields.
By default, Elasticsearch changes the values of text fields as part of analysis. This can make finding exact matches for text field values difficult.
To search text field values, use the match query instead.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
func NewTermQuery ¶
func NewTermQuery() TermQuery
func (*TermQuery) RemoveTerm ¶
type TranspositionsParam ¶
type TranspositionsParam struct {
TranspositionsValue *bool `json:"transpositions,omitempty" bson:"transpositions,omitempty"`
}
func (*TranspositionsParam) SetTranspositions ¶
func (t *TranspositionsParam) SetTranspositions(v bool)
SetTranspositions sets the value of Transpositions to v
func (TranspositionsParam) Transpositions ¶
func (t TranspositionsParam) Transpositions() bool
Transpositions indicates whether edits include transpositions of two adjacent characters (ab → ba). Defaults to true.
type WithAnalyzer ¶
type WithAnalyzer interface { // Analyzer used to convert the text in the query value into tokens. // Defaults to the index-time analyzer mapped for the <field>. If no // analyzer is mapped, the index’s default analyzer is used. (Optional) Analyzer() string // SetAnalyzer sets the Analyzer value to v SetAnalyzer(v string) }
WithAnalyzer is a query with the analyzer param
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html
type WithAutoGenerateSynonymsPhraseQuery ¶
type WithAutoGenerateSynonymsPhraseQuery interface { // AutoGenerateSynonymsPhraseQuery determines if match phrase queries are // automatically created for multi-term synonyms. Defaults to true. AutoGenerateSynonymsPhraseQuery() bool // SetAutoGenerateSynonymsPhraseQuery sets AutoGenerateSynonymsPhraseQueryValue to v SetAutoGenerateSynonymsPhraseQuery(v bool) }
WithAutoGenerateSynonymsPhraseQuery is an interface for the query mixin that adds auto_generate_synonyms_phrase_query param
type WithFuzziness ¶
type WithFuzziness interface { // Fuzziness is the maximum edit distance allowed for matching. See // Fuzziness for valid values and more information. See Fuzziness in the // match query for an example. Fuzziness() string // SetFuzziness sets the FuzzinessValue to v SetFuzziness(str string) // FuzzyRewrite is the method used to rewrite the query. See the rewrite // parameter for valid values and more information. // // If the fuzziness parameter is not 0, the match query uses a fuzzy_rewrite // method of top_terms_blended_freqs_${max_expansions} by default. FuzzyRewrite() Rewrite // SetFuzzyRewrite sets the value of FuzzyRewrite to v SetFuzzyRewrite(v Rewrite) }
WithFuzziness is an interface for queries with fuzziness the parameter
Maximum edit distance allowed for matching. See Fuzziness for valid values and more information.
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness
type WithFuzzyTranspositions ¶
type WithFuzzyTranspositions interface { // FuzzyTranspositions edits for fuzzy matching include transpositions of // two adjacent characters (ab → ba). Defaults to true FuzzyTranspositions() bool // SetFuzzyTranspositions sets FuzzyTranspositions to v SetFuzzyTranspositions(v bool) }
WithFuzzyTranspositions is a query with the fuzzy_transpositions param
If true, edits for fuzzy matching include transpositions of two adjacent characters (ab → ba). Defaults to true
type WithLenient ¶
type WithLenient interface { // Lenient determines whether format-based errors, such as providing a text // query value for a numeric field, are ignored. Defaults to false. Lenient() bool // SetLenient sets Lenient to v SetLenient(v bool) }
WithLenient is a query with the lenient param
type WithMaxExpansions ¶
type WithMaxExpansions interface { // MaxExpansions is the maximum number of variations created. Defaults to 50. MaxExpansions() int SetMaxExpansions(v int) }
WithMaxExpansions is a query with the max_expansions param
Maximum number of variations created. Defaults to 50.
WARNING ¶
Avoid using a high value in the max_expansions parameter, especially if the prefix_length parameter value is 0. High values in the max_expansions parameter can cause poor performance due to the high number of variations examined.
type WithMinimumShouldMatch ¶
type WithMinimumShouldMatch interface { MinimumShouldMatch() string SetMinimumShouldMatch(v string) }
WithMinimumShouldMatch is a query with the minimum_should_match param
Examples of possible values:
"3"
Integers indicate a fixed value regardless of the number of optional clauses.
"-2"
Negative integers indicate that the total number of optional clauses, minus this number should be mandatory
"75%"
Percentages indicate that this percent of the total number of optional clauses are necessary. The number computed from the percentage is rounded down and used as the minimum.
"-25%"
Negative percentages indicate that this percent of the total number of optional clauses can be missing. The number computed from the percentage is rounded down, before being subtracted from the total to determine the minimum.
"3<90%"
A positive integer, followed by the less-than symbol, followed by any of the previously mentioned specifiers is a conditional specification. It indicates that if the number of optional clauses is equal to (or less than) the integer, they are all required, but if it’s greater than the integer, the specification applies. In this example: if there are 1 to 3 clauses they are all required, but for 4 or more clauses only 90% are required.
"2<-25% 9<-3"
Multiple conditional specifications can be separated by spaces, each one only being valid for numbers greater than the one before it. In this example: if there are 1 or 2 clauses both are required, if there are 3-9 clauses all but 25% are required, and if there are more than 9 clauses, all but three are required.
Note ¶
When dealing with percentages, negative values can be used to get different behavior in edge cases. 75% and -25% mean the same thing when dealing with 4 clauses, but when dealing with 5 clauses 75% means 3 are required, but -25% means 4 are required.
If the calculations based on the specification determine that no optional clauses are needed, the usual rules about BooleanQueries still apply at search time (a BooleanQuery containing no required clauses must still match at least one optional clause)
No matter what number the calculation arrives at, a value greater than the number of optional clauses, or a value less than 1 will never be used. (ie: no matter how low or how high the result of the calculation result is, the minimum number of required matches will never be lower than 1 or greater than the number of clauses.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html
type WithOperator ¶
type WithOperator interface { // Operator is the boolean logic used to interpret text in the query value. // Defaults to Or Operator() Operator // SetOperator sets the Operator to v SetOperator(v Operator) }
WithOperator is a query with the operator param
Boolean logic used to interpret text in the query value.
type WithPrefixLength ¶
type WithRewrite ¶
WithRewrite is a query with the rewrite param
type WithTranspositions ¶
type WithTranspositions interface { // Transpositions indicates whether edits include transpositions of two // adjacent characters (ab → ba). Defaults to true. Transpositions() bool // SetTranspositions sets the value of Transpositions to v SetTranspositions(v bool) }
WithTranspositions is an interface for queries with the transpositions param
(Optional, Boolean) Indicates whether edits include transpositions of two adjacent characters (ab → ba). Defaults to true.
type WithZeroTermsQuery ¶
type WithZeroTermsQuery interface { // ZeroTermsQuery indicates whether no documents are returned if the // analyzer removes all tokens, such as when using a stop filter ZeroTermsQuery() ZeroTermsQuery SetZeroTermsQuery(v ZeroTermsQuery) }
type ZeroTermsQuery ¶
type ZeroTermsQuery string
const ( // ZeroTermsQueryNone - No documents are returned if the analyzer removes all // tokens. ZeroTermsQueryNone ZeroTermsQuery = "none" // ZeroTermsALl - Returns all documents, similar to a match_all query. ZeroTermsQueryAll ZeroTermsQuery = "all" )
type ZeroTermsQueryParam ¶
type ZeroTermsQueryParam struct {
ZeroTermsQueryValue *ZeroTermsQuery `json:"zero_terms_query,omitempty" bson:"zero_terms_query,omitempty"`
}
func (*ZeroTermsQueryParam) SetZeroTermsQuery ¶
func (ztq *ZeroTermsQueryParam) SetZeroTermsQuery(v ZeroTermsQuery)
func (ZeroTermsQueryParam) ZeroTermsQuery ¶
func (ztq ZeroTermsQueryParam) ZeroTermsQuery() ZeroTermsQuery
ZeroTermsQuery indicates whether no documents are returned if the analyzer removes all tokens, such as when using a stop filter
Source Files ¶
- analyzer.go
- autoGenerateSynonymsPhraseQuery.go
- boost.go
- builder.go
- caseInsensitive.go
- docs.go
- docvalueFields.go
- errors.go
- exists.go
- field.go
- fuzziness.go
- fuzzy.go
- fuzzyTranspositions.go
- ids.go
- indicesBoost.go
- lenient.go
- match.go
- matchBooleanPrefix.go
- matchPhrase.go
- matchPhrasePrefix.go
- maxExpansions.go
- minimumShouldMatch.go
- operator.go
- pointInTime.go
- prefix.go
- prefixLength.go
- query.go
- queryType.go
- rewrite.go
- runtimeMappings.go
- search.go
- slop.go
- source.go
- term.go
- transpositions.go
- zeroTerms.go