Skip to content

Simple Query String

A simple query string query parses a provided query string and searches for documents using the specified fields and options. It supports a variety of query options to refine the search.

Example

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

query, err := effdsl.Define(
    effdsl.WithQuery(
        sqs.SimpleQueryString(
            `"fried eggs" +(eggplant | potato) -frittata`,
            sqs.WithFields("title^5", "body"),
            sqs.WithDefaultOperator(sqs.AND),
        ),
    ),
)

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

Parameters

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

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

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

    • OR: For example, a query value of "capital of Hungary" is interpreted as "capital OR of OR Hungary".
    • AND: For example, a query value of "capital of Hungary" is interpreted as "capital AND of AND Hungary".
  • 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 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.

  • WithFlags (string)
    (Optional, Functional option) List of enabled operators for the simple query string syntax. Defaults to ALL (all operators). See Limit operators for valid values.

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

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

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

Additional Information

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