Class MatchQueryBuilder

All Implemented Interfaces:
NamedWriteable, Writeable, QueryBuilder, Rewriteable<QueryBuilder>, ToXContent, ToXContentObject

public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder>
Match query is a query that analyzes the text and constructs a query as the result of the analysis.
  • Field Details


      public static final ParseField ZERO_TERMS_QUERY_FIELD

      @Deprecated public static final ParseField CUTOFF_FREQUENCY_FIELD
      Since max_optimization optimization landed in 7.0, normal MatchQuery will achieve the same result without any configuration.

      public static final ParseField LENIENT_FIELD

      public static final ParseField FUZZY_TRANSPOSITIONS_FIELD

      public static final ParseField FUZZY_REWRITE_FIELD

      public static final ParseField MINIMUM_SHOULD_MATCH_FIELD

      public static final ParseField OPERATOR_FIELD

      public static final ParseField MAX_EXPANSIONS_FIELD

      public static final ParseField PREFIX_LENGTH_FIELD

      public static final ParseField ANALYZER_FIELD

      public static final ParseField QUERY_FIELD

      public static final ParseField GENERATE_SYNONYMS_PHRASE_QUERY
    • NAME

      public static final String NAME
      The name for the match query
      See Also:

      public static final Operator DEFAULT_OPERATOR
      The default mode terms are combined in a match query
  • Constructor Details

    • MatchQueryBuilder

      public MatchQueryBuilder(String fieldName, Object value)
      Constructs a new match query.
    • MatchQueryBuilder

      public MatchQueryBuilder(StreamInput in) throws IOException
      Read from a stream.
  • Method Details

    • doWriteTo

      protected void doWriteTo(StreamOutput out) throws IOException
      Specified by:
      doWriteTo in class AbstractQueryBuilder<MatchQueryBuilder>
    • fieldName

      public String fieldName()
      Returns the field name used in this query.
    • value

      public Object value()
      Returns the value used in this query.
    • operator

      public MatchQueryBuilder operator(Operator operator)
      Sets the operator to use when using a boolean query. Defaults to OR.
    • operator

      public Operator operator()
      Returns the operator to use in a boolean query.
    • analyzer

      public MatchQueryBuilder analyzer(String analyzer)
      Explicitly set the analyzer to use. Defaults to use explicit mapping config for the field, or, if not set, the default search analyzer.
    • analyzer

      public String analyzer()
      Get the analyzer to use, if previously set, otherwise null
    • fuzziness

      public MatchQueryBuilder fuzziness(Object fuzziness)
      Sets the fuzziness used when evaluated to a fuzzy query type. Defaults to "AUTO".
    • fuzziness

      public Fuzziness fuzziness()
      Gets the fuzziness used when evaluated to a fuzzy query type.
    • prefixLength

      public MatchQueryBuilder prefixLength(int prefixLength)
      Sets the length of a length of common (non-fuzzy) prefix for fuzzy match queries
      prefixLength - non-negative length of prefix
      IllegalArgumentException - in case the prefix is negative
    • prefixLength

      public int prefixLength()
      Gets the length of a length of common (non-fuzzy) prefix for fuzzy match queries
    • maxExpansions

      public MatchQueryBuilder maxExpansions(int maxExpansions)
      When using fuzzy or prefix type query, the number of term expansions to use.
    • maxExpansions

      public int maxExpansions()
      Get the (optional) number of term expansions when using fuzzy or prefix type query.
    • cutoffFrequency

      @Deprecated public MatchQueryBuilder cutoffFrequency(float cutoff)
      see CUTOFF_FREQUENCY_FIELD for more details
      Set a cutoff value in [0..1] (or absolute number >=1) representing the maximum threshold of a terms document frequency to be considered a low frequency term.
    • cutoffFrequency

      public Float cutoffFrequency()
      Gets the optional cutoff value, can be null if not set previously
    • minimumShouldMatch

      public MatchQueryBuilder minimumShouldMatch(String minimumShouldMatch)
      Sets optional minimumShouldMatch value to apply to the query
    • minimumShouldMatch

      public String minimumShouldMatch()
      Gets the minimumShouldMatch value
    • fuzzyRewrite

      public MatchQueryBuilder fuzzyRewrite(String fuzzyRewrite)
      Sets the fuzzy_rewrite parameter controlling how the fuzzy query will get rewritten
    • fuzzyRewrite

      public String fuzzyRewrite()
      Get the fuzzy_rewrite parameter
      See Also:
    • fuzzyTranspositions

      public MatchQueryBuilder fuzzyTranspositions(boolean fuzzyTranspositions)
      Sets whether transpositions are supported in fuzzy queries.

      The default metric used by fuzzy queries to determine a match is the Damerau-Levenshtein distance formula which supports transpositions. Setting transposition to false will switch to classic Levenshtein distance.
      If not set, Damerau-Levenshtein distance metric will be used.

    • fuzzyTranspositions

      public boolean fuzzyTranspositions()
      Gets the fuzzy query transposition setting.
    • lenient

      public MatchQueryBuilder lenient(boolean lenient)
      Sets whether format based failures will be ignored.
    • lenient

      public boolean lenient()
      Gets leniency setting that controls if format based failures will be ignored.
    • zeroTermsQuery

      public MatchQueryBuilder zeroTermsQuery(ZeroTermsQueryOption zeroTermsQuery)
      Sets query to use in case no query terms are available, e.g. after analysis removed them. Defaults to ZeroTermsQueryOption.NONE, but can be set to ZeroTermsQueryOption.ALL instead.
    • zeroTermsQuery

      public ZeroTermsQueryOption zeroTermsQuery()
      Returns the setting for handling zero terms queries.
    • autoGenerateSynonymsPhraseQuery

      public MatchQueryBuilder autoGenerateSynonymsPhraseQuery(boolean enable)
    • autoGenerateSynonymsPhraseQuery

      public boolean autoGenerateSynonymsPhraseQuery()
      Whether phrase queries should be automatically generated for multi terms synonyms. Defaults to true.
    • doXContent

      public void doXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
      Specified by:
      doXContent in class AbstractQueryBuilder<MatchQueryBuilder>
    • doRewrite

      protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException
      doRewrite in class AbstractQueryBuilder<MatchQueryBuilder>
    • doToQuery

      protected doToQuery(SearchExecutionContext context) throws IOException
      Specified by:
      doToQuery in class AbstractQueryBuilder<MatchQueryBuilder>
    • doEquals

      protected boolean doEquals(MatchQueryBuilder other)
      Description copied from class: AbstractQueryBuilder
      Indicates whether some other QueryBuilder object of the same type is "equal to" this one.
      Specified by:
      doEquals in class AbstractQueryBuilder<MatchQueryBuilder>
    • doHashCode

      protected int doHashCode()
      Specified by:
      doHashCode in class AbstractQueryBuilder<MatchQueryBuilder>
    • getWriteableName

      public String getWriteableName()
      Description copied from interface: NamedWriteable
      Returns the name of the writeable object
    • fromXContent

      public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOException