Class SimpleQueryStringBuilder

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

    public class SimpleQueryStringBuilder
    extends AbstractQueryBuilder<SimpleQueryStringBuilder>
    SimpleQuery is a query parser that acts similar to a query_string query, but won't throw exceptions for any weird string syntax. It supports the following:
    • '+' specifies AND operation: token1+token2
    • '|' specifies OR operation: token1|token2
    • '-' negates a single token: -token0
    • '"' creates phrases of terms: "term1 term2 ..."
    • '*' at the end of terms specifies prefix query: term*
    • '(' and ')' specifies precedence: token1 + (token2 | token3)
    • '~N' at the end of terms specifies fuzzy query: term~1
    • '~N' at the end of phrases specifies near/slop query: "term1 term2"~5

    See: SimpleQueryStringQueryParser for more information.

    This query supports these options:

    Required: query - query text to be converted into other queries

    Optional: analyzer - anaylzer to be used for analyzing tokens to determine which kind of query they should be converted into, defaults to "standard" default_operator - default operator for boolean queries, defaults to OR fields - fields to search, defaults to _all if not set, allows boosting a field with ^n For more detailed explanation of the query string syntax see also the online documentation.

    • Field Detail


        public static final boolean DEFAULT_LENIENT
        Default for using lenient query parsing.
        See Also:
        Constant Field Values

        public static final boolean DEFAULT_ANALYZE_WILDCARD
        Default for wildcard analysis.
        See Also:
        Constant Field Values

        public static final Operator DEFAULT_OPERATOR
        Default for default operator to use for linking boolean clauses.

        public static final int DEFAULT_FLAGS
        Default for search flags to use.

        public static final int DEFAULT_FUZZY_PREFIX_LENGTH
        Default for prefix length in fuzzy queries.
        See Also:
        Constant Field Values

        public static final int DEFAULT_FUZZY_MAX_EXPANSIONS
        Default number of terms fuzzy queries will expand to.
        See Also:
        Constant Field Values

        public static final boolean DEFAULT_FUZZY_TRANSPOSITIONS
        Default for using transpositions in fuzzy queries.
        See Also:
        Constant Field Values
      • NAME

        public static final java.lang.String NAME
        Name for (de-)serialization.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SimpleQueryStringBuilder

        public SimpleQueryStringBuilder​(java.lang.String queryText)
        Construct a new simple query with this query string.
      • SimpleQueryStringBuilder

        public SimpleQueryStringBuilder​(StreamInput in)
        Read from a stream.
    • Method Detail

      • value

        public java.lang.String value()
        Returns the text to parse the query from.
      • field

        public SimpleQueryStringBuilder field​(java.lang.String field,
                                              float boost)
        Add a field to run the query against with a specific boost.
      • fields

        public SimpleQueryStringBuilder fields​(java.util.Map<java.lang.String,​java.lang.Float> fields)
        Add several fields to run the query against with a specific boost.
      • fields

        public java.util.Map<java.lang.String,​java.lang.Float> fields()
        Returns the fields including their respective boosts to run the query against.
      • analyzer

        public SimpleQueryStringBuilder analyzer​(java.lang.String analyzer)
        Specify an analyzer to use for the query.
      • analyzer

        public java.lang.String analyzer()
        Returns the analyzer to use for the query.
      • useAllFields

        public java.lang.Boolean useAllFields()
      • defaultOperator

        public SimpleQueryStringBuilder defaultOperator​(Operator defaultOperator)
        Specify the default operator for the query. Defaults to "OR" if no operator is specified.
      • defaultOperator

        public Operator defaultOperator()
        Returns the default operator for the query.
      • quoteFieldSuffix

        public SimpleQueryStringBuilder quoteFieldSuffix​(java.lang.String suffix)
        Set the suffix to append to field names for phrase matching.
      • quoteFieldSuffix

        public java.lang.String quoteFieldSuffix()
        Return the suffix to append to field names for phrase matching.
      • lenient

        public SimpleQueryStringBuilder lenient​(boolean lenient)
        Specifies whether query parsing should be lenient. Defaults to false.
      • lenient

        public boolean lenient()
        Returns whether query parsing should be lenient.
      • analyzeWildcard

        public SimpleQueryStringBuilder analyzeWildcard​(boolean analyzeWildcard)
        Specifies whether wildcards should be analyzed. Defaults to false.
      • analyzeWildcard

        public boolean analyzeWildcard()
        Returns whether wildcards should by analyzed.
      • minimumShouldMatch

        public SimpleQueryStringBuilder minimumShouldMatch​(java.lang.String minimumShouldMatch)
        Specifies the minimumShouldMatch to apply to the resulting query should that be a Boolean query.
      • minimumShouldMatch

        public java.lang.String minimumShouldMatch()
        Returns the minimumShouldMatch to apply to the resulting query should that be a Boolean query.
      • autoGenerateSynonymsPhraseQuery

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

        public int fuzzyPrefixLength()
      • fuzzyMaxExpansions

        public int fuzzyMaxExpansions()
      • fuzzyTranspositions

        public boolean fuzzyTranspositions()
      • fuzzyTranspositions

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

      • getWriteableName

        public java.lang.String getWriteableName()
        Description copied from interface: NamedWriteable
        Returns the name of the writeable object