Skip to content

Multi Match Query

A multi match query searches multiple fields for the provided query text. It is useful when the same text should be matched against a set of fields with different weights or options.

Example

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

query, err := effdsl.Define(
    effdsl.WithQuery(
        mmq.MultiMatchQuery(
            "quick brown fox",
            mmq.WithFields("title", "message"),
            mmq.WithType(mmq.BestFields),
        ),
    ),
)

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

Parameters

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

  • WithFields (...string) (Optional, Functional option) Fields to search. Each field can include a boost using the field^boost syntax.

  • WithType (MultiMatchType) (Optional, Functional option) Type of multi match query. Valid values are:

    • best_fields
    • most_fields
    • cross_fields
    • phrase
    • phrase_prefix
    • bool_prefix
  • WithOperator (Operator) (Optional, Functional option) Boolean logic used to interpret text in the query. Valid values are:

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

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

  • WithFuzziness (string) (Optional, Functional option) Fuzziness used for fuzzy matching.

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

  • WithMaxExpansions (int) (Optional, Functional option) Maximum number of terms the query will expand to for fuzzy matching.

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

  • WithTieBreaker (float64) (Optional, Functional option) Tie breaker used when best_fields type is specified.

  • WithLenient (bool) (Optional, Functional option) If true, format-based errors, such as providing text for a numeric field, are ignored.

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

    • none (Default)
    • all
  • WithAutoGenerateSynonymsPhraseQuery (bool) (Optional, Functional option) If true, match phrase queries are automatically created for multi-term synonyms.

Additional Information

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