Class MultiMatchQueryBuilder

All Implemented Interfaces:
NamedWriteable, Writeable, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentObject, QueryBuilder, Rewriteable<QueryBuilder>

public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQueryBuilder>
Same as MatchQueryBuilder but supports multiple fields.
  • Field Details

  • Constructor Details

    • MultiMatchQueryBuilder

      public MultiMatchQueryBuilder(Object value, String... fields)
      Constructs a new text query.
    • MultiMatchQueryBuilder

      public MultiMatchQueryBuilder(StreamInput in) throws IOException
      Read from a stream.
      Throws:
      IOException
  • Method Details

    • getType

      public MultiMatchQueryBuilder.Type getType()
      Returns the type (for testing)
    • doWriteTo

      protected void doWriteTo(StreamOutput out) throws IOException
      Specified by:
      doWriteTo in class AbstractQueryBuilder<MultiMatchQueryBuilder>
      Throws:
      IOException
    • value

      public Object value()
    • field

      public MultiMatchQueryBuilder field(String field)
      Adds a field to run the multi match against.
    • field

      public MultiMatchQueryBuilder field(String field, float boost)
      Adds a field to run the multi match against with a specific boost.
    • fields

      public MultiMatchQueryBuilder fields(Map<String,Float> fields)
      Add several fields to run the query against with a specific boost.
    • fields

      public Map<String,Float> fields()
    • type

      Sets the type of the text query.
    • type

      public MultiMatchQueryBuilder type(Object type)
      Sets the type of the text query.
    • type

    • operator

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

      public Operator operator()
    • analyzer

      public MultiMatchQueryBuilder 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()
    • slop

      public MultiMatchQueryBuilder slop(int slop)
      Set the phrase slop if evaluated to a phrase query type.
    • slop

      public int slop()
    • fuzziness

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

      public Fuzziness fuzziness()
    • prefixLength

      public MultiMatchQueryBuilder prefixLength(int prefixLength)
    • prefixLength

      public int prefixLength()
    • maxExpansions

      public MultiMatchQueryBuilder maxExpansions(int maxExpansions)
      When using fuzzy or prefix type query, the number of term expansions to use. Defaults to unbounded so its recommended to set it to a reasonable value for faster execution.
    • maxExpansions

      public int maxExpansions()
    • minimumShouldMatch

      public MultiMatchQueryBuilder minimumShouldMatch(String minimumShouldMatch)
    • minimumShouldMatch

      public String minimumShouldMatch()
    • fuzzyRewrite

      public MultiMatchQueryBuilder fuzzyRewrite(String fuzzyRewrite)
    • fuzzyRewrite

      public String fuzzyRewrite()
    • tieBreaker

      public MultiMatchQueryBuilder tieBreaker(float tieBreaker)

      Tie-Breaker for "best-match" disjunction queries (OR-Queries). The tie breaker capability allows documents that match more than one query clause (in this case on more than one field) to be scored better than documents that match only the best of the fields, without confusing this with the better case of two distinct matches in the multiple fields.

      A tie-breaker value of 1.0 is interpreted as a signal to score queries as "most-match" queries where all matching query clauses are considered for scoring.

      See Also:
      MultiMatchQueryBuilder.Type
    • tieBreaker

      public MultiMatchQueryBuilder tieBreaker(Float tieBreaker)

      Tie-Breaker for "best-match" disjunction queries (OR-Queries). The tie breaker capability allows documents that match more than one query clause (in this case on more than one field) to be scored better than documents that match only the best of the fields, without confusing this with the better case of two distinct matches in the multiple fields.

      A tie-breaker value of 1.0 is interpreted as a signal to score queries as "most-match" queries where all matching query clauses are considered for scoring.

      See Also:
      MultiMatchQueryBuilder.Type
    • tieBreaker

      public Float tieBreaker()
    • lenient

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

      public boolean lenient()
    • cutoffFrequency

      @Deprecated public MultiMatchQueryBuilder cutoffFrequency(float cutoff)
      Deprecated.
      Since max_score optimization landed in 7.0, normal MultiMatchQuery will achieve the same result without any configuration.
      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

      @Deprecated public MultiMatchQueryBuilder cutoffFrequency(Float cutoff)
      Deprecated.
      Since max_score optimization landed in 7.0, normal MultiMatchQuery will achieve the same result without any configuration.
      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()
    • zeroTermsQuery

      public MultiMatchQueryBuilder zeroTermsQuery(ZeroTermsQueryOption zeroTermsQuery)
    • zeroTermsQuery

      public ZeroTermsQueryOption zeroTermsQuery()
    • autoGenerateSynonymsPhraseQuery

      public MultiMatchQueryBuilder autoGenerateSynonymsPhraseQuery(boolean enable)
    • autoGenerateSynonymsPhraseQuery

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

      public boolean fuzzyTranspositions()
    • fuzzyTranspositions

      public MultiMatchQueryBuilder 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.

    • doXContent

      public void doXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws IOException
      Specified by:
      doXContent in class AbstractQueryBuilder<MultiMatchQueryBuilder>
      Throws:
      IOException
    • fromXContent

      public static MultiMatchQueryBuilder fromXContent(org.elasticsearch.common.xcontent.XContentParser parser) throws IOException
      Throws:
      IOException
    • getWriteableName

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

      protected org.apache.lucene.search.Query doToQuery(SearchExecutionContext context) throws IOException
      Specified by:
      doToQuery in class AbstractQueryBuilder<MultiMatchQueryBuilder>
      Throws:
      IOException
    • doHashCode

      protected int doHashCode()
      Specified by:
      doHashCode in class AbstractQueryBuilder<MultiMatchQueryBuilder>
    • doEquals

      protected boolean doEquals(MultiMatchQueryBuilder 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<MultiMatchQueryBuilder>