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"
    mppq "github.com/sdqri/effdsl/v2/queries/matchphraseprefixquery"
)

query, err := effdsl.Define(
    effdsl.WithQuery(
        mppq.MatchPhrasePrefixQuery(
            "field_name",
            "some phrase prefix query",
            mppq.WithAnalyzer("my_analyzer"),
            mppq.WithSlop(2),
            mppq.WithMaxExpansions(10),
        ),
    ),
)

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

Parameters

  • Field (string)
    (Required, positional) The field to search. This is a required parameter.

  • Query (string)
    (Required, positional) The text to search for in the provided field. This is a required parameter.

  • WithAnalyzer (string)
    (Optional, Functional option) 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.

  • WithSlop (int)
    (Optional, Functional option) Maximum number of positions allowed between matching tokens for phrases. Defaults to 0.

  • WithMaxExpansions (int)
    (Optional, Functional option) Maximum number of terms to which the last provided term will expand. Defaults to not expanding terms.

  • WithZeroTermsQuery (ZeroTerms)
    (Optional, Functional option) Indicates what to do when the analyzed text contains no terms. Valid values are:

    • none (Default): No documents are returned if the analyzer removes all tokens.
    • all: Returns all documents, similar to a match_all query.

Additional Information

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

"github.com/sdqri/effdsl/v2"
sqs "github.com/sdqri/effdsl/v2/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.