Class SimpleQueryStringBuilder
- java.lang.Object
-
- org.elasticsearch.index.query.AbstractQueryBuilder<SimpleQueryStringBuilder>
-
- org.elasticsearch.index.query.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:- '
+' specifiesANDoperation:token1+token2 - '
|' specifiesORoperation: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:
SimpleQueryStringQueryParserfor more information.This query supports these options:
Required:
query- query text to be converted into other queriesOptional:
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 ORfields- 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_ANALYZE_WILDCARDDefault for wildcard analysis.static intDEFAULT_FLAGSDefault for search flags to use.static intDEFAULT_FUZZY_MAX_EXPANSIONSDefault number of terms fuzzy queries will expand to.static intDEFAULT_FUZZY_PREFIX_LENGTHDefault for prefix length in fuzzy queries.static booleanDEFAULT_FUZZY_TRANSPOSITIONSDefault for using transpositions in fuzzy queries.static booleanDEFAULT_LENIENTDefault for using lenient query parsing.static OperatorDEFAULT_OPERATORDefault for default operator to use for linking boolean clauses.static java.lang.StringNAMEName for (de-)serialization.-
Fields inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
boost, BOOST_FIELD, DEFAULT_BOOST, NAME_FIELD, queryName
-
Fields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDS
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description SimpleQueryStringBuilder(java.lang.String queryText)Construct a new simple query with this query string.SimpleQueryStringBuilder(StreamInput in)Read from a stream.
-
Method Summary
Modifier and Type Method Description java.lang.Stringanalyzer()Returns the analyzer to use for the query.SimpleQueryStringBuilderanalyzer(java.lang.String analyzer)Specify an analyzer to use for the query.booleananalyzeWildcard()Returns whether wildcards should by analyzed.SimpleQueryStringBuilderanalyzeWildcard(boolean analyzeWildcard)Specifies whether wildcards should be analyzed.booleanautoGenerateSynonymsPhraseQuery()Whether phrase queries should be automatically generated for multi terms synonyms.SimpleQueryStringBuilderautoGenerateSynonymsPhraseQuery(boolean value)OperatordefaultOperator()Returns the default operator for the query.SimpleQueryStringBuilderdefaultOperator(Operator defaultOperator)Specify the default operator for the query.protected booleandoEquals(SimpleQueryStringBuilder other)Indicates whether some otherQueryBuilderobject of the same type is "equal to" this one.protected intdoHashCode()protected org.apache.lucene.search.QuerydoToQuery(QueryShardContext context)protected voiddoWriteTo(StreamOutput out)protected voiddoXContent(XContentBuilder builder, ToXContent.Params params)SimpleQueryStringBuilderfield(java.lang.String field)Add a field to run the query against.SimpleQueryStringBuilderfield(java.lang.String field, float boost)Add a field to run the query against with a specific boost.java.util.Map<java.lang.String,java.lang.Float>fields()Returns the fields including their respective boosts to run the query against.SimpleQueryStringBuilderfields(java.util.Map<java.lang.String,java.lang.Float> fields)Add several fields to run the query against with a specific boost.SimpleQueryStringBuilderflags(SimpleQueryStringFlag... flags)Specify the enabled features of the SimpleQueryString.static SimpleQueryStringBuilderfromXContent(XContentParser parser)intfuzzyMaxExpansions()SimpleQueryStringBuilderfuzzyMaxExpansions(int fuzzyMaxExpansions)intfuzzyPrefixLength()SimpleQueryStringBuilderfuzzyPrefixLength(int fuzzyPrefixLength)booleanfuzzyTranspositions()SimpleQueryStringBuilderfuzzyTranspositions(boolean fuzzyTranspositions)Sets whether transpositions are supported in fuzzy queries.java.lang.StringgetWriteableName()Returns the name of the writeable objectbooleanlenient()Returns whether query parsing should be lenient.SimpleQueryStringBuilderlenient(boolean lenient)Specifies whether query parsing should be lenient.java.lang.StringminimumShouldMatch()Returns the minimumShouldMatch to apply to the resulting query should that be a Boolean query.SimpleQueryStringBuilderminimumShouldMatch(java.lang.String minimumShouldMatch)Specifies the minimumShouldMatch to apply to the resulting query should that be a Boolean query.java.lang.StringquoteFieldSuffix()Return the suffix to append to field names for phrase matching.SimpleQueryStringBuilderquoteFieldSuffix(java.lang.String suffix)Set the suffix to append to field names for phrase matching.java.lang.Stringvalue()Returns the text to parse the query from.-
Methods inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
addValidationError, boost, boost, checkNegativeBoost, declareStandardFields, doRewrite, equals, extractInnerHitBuilders, getName, hashCode, parseInnerQueryBuilder, printBoostAndQueryName, queryName, queryName, requireValue, rewrite, throwParsingExceptionOnMultipleFields, toQuery, toString, toXContent, writeTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
DEFAULT_LENIENT
public static final boolean DEFAULT_LENIENT
Default for using lenient query parsing.- See Also:
- Constant Field Values
-
DEFAULT_ANALYZE_WILDCARD
public static final boolean DEFAULT_ANALYZE_WILDCARD
Default for wildcard analysis.- See Also:
- Constant Field Values
-
DEFAULT_OPERATOR
public static final Operator DEFAULT_OPERATOR
Default for default operator to use for linking boolean clauses.
-
DEFAULT_FLAGS
public static final int DEFAULT_FLAGS
Default for search flags to use.
-
DEFAULT_FUZZY_PREFIX_LENGTH
public static final int DEFAULT_FUZZY_PREFIX_LENGTH
Default for prefix length in fuzzy queries.- See Also:
- Constant Field Values
-
DEFAULT_FUZZY_MAX_EXPANSIONS
public static final int DEFAULT_FUZZY_MAX_EXPANSIONS
Default number of terms fuzzy queries will expand to.- See Also:
- Constant Field Values
-
DEFAULT_FUZZY_TRANSPOSITIONS
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) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
doWriteTo
protected void doWriteTo(StreamOutput out) throws java.io.IOException
- Specified by:
doWriteToin classAbstractQueryBuilder<SimpleQueryStringBuilder>- Throws:
java.io.IOException
-
value
public java.lang.String value()
Returns the text to parse the query from.
-
field
public SimpleQueryStringBuilder field(java.lang.String field)
Add a field to run the query against.
-
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.
-
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.
-
flags
public SimpleQueryStringBuilder flags(SimpleQueryStringFlag... flags)
Specify the enabled features of the SimpleQueryString. Defaults to ALL if none are specified.
-
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 SimpleQueryStringBuilder autoGenerateSynonymsPhraseQuery(boolean value)
-
autoGenerateSynonymsPhraseQuery
public boolean autoGenerateSynonymsPhraseQuery()
Whether phrase queries should be automatically generated for multi terms synonyms. Defaults totrue.
-
fuzzyPrefixLength
public SimpleQueryStringBuilder fuzzyPrefixLength(int fuzzyPrefixLength)
-
fuzzyPrefixLength
public int fuzzyPrefixLength()
-
fuzzyMaxExpansions
public SimpleQueryStringBuilder fuzzyMaxExpansions(int fuzzyMaxExpansions)
-
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.
-
doToQuery
protected org.apache.lucene.search.Query doToQuery(QueryShardContext context) throws java.io.IOException
- Specified by:
doToQueryin classAbstractQueryBuilder<SimpleQueryStringBuilder>- Throws:
java.io.IOException
-
doXContent
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
doXContentin classAbstractQueryBuilder<SimpleQueryStringBuilder>- Throws:
java.io.IOException
-
fromXContent
public static SimpleQueryStringBuilder fromXContent(XContentParser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
getWriteableName
public java.lang.String getWriteableName()
Description copied from interface:NamedWriteableReturns the name of the writeable object
-
doHashCode
protected int doHashCode()
- Specified by:
doHashCodein classAbstractQueryBuilder<SimpleQueryStringBuilder>
-
doEquals
protected boolean doEquals(SimpleQueryStringBuilder other)
Description copied from class:AbstractQueryBuilderIndicates whether some otherQueryBuilderobject of the same type is "equal to" this one.- Specified by:
doEqualsin classAbstractQueryBuilder<SimpleQueryStringBuilder>
-
-