Skip to content

Query String Query

A query string query parses and executes a search query based on a query string syntax. It allows for flexible and complex query expressions.

Example

import (
    es "github.com/elastic/go-elasticsearch/v8"
    "github.com/sdqri/effdsl/v2"
    qs "github.com/sdqri/effdsl/queries/querystring"
)

query, err := effdsl.Define(
    effdsl.WithQuery(
        qs.QueryString(
            "alice",
            qs.WithFields("first_name", "last_name")
            qs.WithBoost(1.5),
            qs.WithFuzziness("AUTO"),
        ),
    ),
)

res, err := es.Search(
    es.Search.WithBody(strings.NewReader(query)),
)

Parameters

  • Query (string)
    (Required, positional) The query string to parse and use for search. This is a required parameter.

  • WithDefaultField (string)
    (Optional, Functional option) Default field to search if no field is provided in the query string.

  • WithAllowLeadingWildcard ()
    (Optional, Functional option) If true, wildcard characters * and ? are allowed as the first character in the query string. Defaults to true.

  • WithAnalyzeWildcard ()
    (Optional, Functional option) If true, the query attempts to analyze wildcard terms in the query string. Defaults to false.

  • WithAnalyzer (string)
    (Optional, Functional option) Analyzer used to convert the text in the query string into tokens.

  • WithAutoGenerateSynonymsPhrase (bool)
    (Optional, Functional option) If true, match phrase queries are automatically created for multi-term synonyms. Defaults to true.

  • WithBoost (float64)
    (Optional, Functional option) Floating point number used to adjust the relevance scores of the query.

  • WithDefaultOperator (Operator)
    (Optional, Functional option) Default boolean logic used to interpret text in the query string. Valid values are:

    • OR: Logical OR.
    • AND: Logical AND.
  • WithEnablePositionIncrements (bool)
    (Optional, Functional option) If true, enable position increments in queries constructed from the query string search.

  • WithFields (...string)
    (Optional, Functional option) Array of fields to search. Supports wildcards *.

  • WithFuzziness (string)
    (Optional, Functional option) Maximum edit distance allowed for fuzzy matching.

  • WithFuzzyMaxExpansions (int)
    (Optional, Functional option) Maximum number of terms for fuzzy matching expansion.

  • WithFuzzyPrefixLength (int)
    (Optional, Functional option) Number of beginning characters left unchanged for fuzzy matching.

  • WithFuzzyTranspositions (bool)
    (Optional, Functional option) If true, edits for fuzzy matching include transpositions of adjacent characters.

  • WithLenient (bool)
    (Optional, Functional option) If true, format-based errors are ignored.

  • WithMaxDeterminizedStates (int)
    (Optional, Functional option) Maximum number of automaton states required for the query.

  • WithMinimumShouldMatch (string)
    (Optional, Functional option) Minimum number of clauses that must match for a document to be returned.

  • WithQuoteAnalyzer (string)
    (Optional, Functional option) Analyzer used to convert quoted text in the query string into tokens.

  • WithPhraseSlop (int)
    (Optional, Functional option) Maximum number of positions allowed between matching tokens for phrases.

  • WithQuoteFieldSuffix (string)
    (Optional, Functional option) Suffix appended to quoted text in the query string.

  • WithRewrite (Rewrite)
    (Optional, Functional option) Method used to rewrite the query. Valid values are:

    • constant_score
    • scoring_boolean
    • constant_score_boolean
    • top_terms_N
    • top_terms_boost_N
    • top_terms_blended_freqs_N
  • WithTimeZone (string)
    (Optional, Functional option) UTC offset or IANA time zone used to convert date values in the query string to UTC.

Additional Information

For more details on the query string query and its parameters, refer to the official Elasticsearch documentation on query string queries.