Class SimpleQueryStringBuilder
- All Implemented Interfaces:
NamedWriteable
,Writeable
,org.elasticsearch.common.xcontent.ToXContent
,org.elasticsearch.common.xcontent.ToXContentObject
,QueryBuilder
,Rewriteable<QueryBuilder>
- '
+
' specifiesAND
operation:token1+token2
- '
|
' specifiesOR
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
Modifier and TypeFieldDescriptionstatic boolean
Default for wildcard analysis.static int
Default for search flags to use.static int
Default number of terms fuzzy queries will expand to.static int
Default for prefix length in fuzzy queries.static boolean
Default for using transpositions in fuzzy queries.static boolean
Default for using lenient query parsing.static Operator
Default for default operator to use for linking boolean clauses.static String
Name 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
ConstructorDescriptionSimpleQueryStringBuilder(String queryText)
Construct a new simple query with this query string.Read from a stream. -
Method Summary
Modifier and TypeMethodDescriptionanalyzer()
Returns the analyzer to use for the query.Specify an analyzer to use for the query.boolean
Returns whether wildcards should by analyzed.analyzeWildcard(boolean analyzeWildcard)
Specifies whether wildcards should be analyzed.boolean
Whether phrase queries should be automatically generated for multi terms synonyms.autoGenerateSynonymsPhraseQuery(boolean value)
Returns the default operator for the query.defaultOperator(Operator defaultOperator)
Specify the default operator for the query.protected boolean
doEquals(SimpleQueryStringBuilder other)
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.protected int
protected org.apache.lucene.search.Query
doToQuery(SearchExecutionContext context)
protected void
doWriteTo(StreamOutput out)
protected void
doXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
Add a field to run the query against.Add a field to run the query against with a specific boost.fields()
Returns the fields including their respective boosts to run the query against.Add several fields to run the query against with a specific boost.flags(SimpleQueryStringFlag... flags)
Specify the enabled features of the SimpleQueryString.static SimpleQueryStringBuilder
fromXContent(org.elasticsearch.common.xcontent.XContentParser parser)
int
fuzzyMaxExpansions(int fuzzyMaxExpansions)
int
fuzzyPrefixLength(int fuzzyPrefixLength)
boolean
fuzzyTranspositions(boolean fuzzyTranspositions)
Sets whether transpositions are supported in fuzzy queries.Returns the name of the writeable objectboolean
lenient()
Returns whether query parsing should be lenient.lenient(boolean lenient)
Specifies whether query parsing should be lenient.Returns the minimumShouldMatch to apply to the resulting query should that be a Boolean query.minimumShouldMatch(String minimumShouldMatch)
Specifies the minimumShouldMatch to apply to the resulting query should that be a Boolean query.Return the suffix to append to field names for phrase matching.quoteFieldSuffix(String suffix)
Set the suffix to append to field names for phrase matching.value()
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, 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 Details
-
DEFAULT_LENIENT
public static final boolean DEFAULT_LENIENTDefault for using lenient query parsing.- See Also:
- Constant Field Values
-
DEFAULT_ANALYZE_WILDCARD
public static final boolean DEFAULT_ANALYZE_WILDCARDDefault for wildcard analysis.- See Also:
- Constant Field Values
-
DEFAULT_OPERATOR
Default for default operator to use for linking boolean clauses. -
DEFAULT_FLAGS
public static final int DEFAULT_FLAGSDefault for search flags to use. -
DEFAULT_FUZZY_PREFIX_LENGTH
public static final int DEFAULT_FUZZY_PREFIX_LENGTHDefault for prefix length in fuzzy queries.- See Also:
- Constant Field Values
-
DEFAULT_FUZZY_MAX_EXPANSIONS
public static final int DEFAULT_FUZZY_MAX_EXPANSIONSDefault number of terms fuzzy queries will expand to.- See Also:
- Constant Field Values
-
DEFAULT_FUZZY_TRANSPOSITIONS
public static final boolean DEFAULT_FUZZY_TRANSPOSITIONSDefault for using transpositions in fuzzy queries.- See Also:
- Constant Field Values
-
NAME
Name for (de-)serialization.- See Also:
- Constant Field Values
-
-
Constructor Details
-
SimpleQueryStringBuilder
Construct a new simple query with this query string. -
SimpleQueryStringBuilder
Read from a stream.- Throws:
IOException
-
-
Method Details
-
doWriteTo
- Specified by:
doWriteTo
in classAbstractQueryBuilder<SimpleQueryStringBuilder>
- Throws:
IOException
-
value
Returns the text to parse the query from. -
field
Add a field to run the query against. -
field
Add a field to run the query against with a specific boost. -
fields
Add several fields to run the query against with a specific boost. -
fields
Returns the fields including their respective boosts to run the query against. -
analyzer
Specify an analyzer to use for the query. -
analyzer
Returns the analyzer to use for the query. -
defaultOperator
Specify the default operator for the query. Defaults to "OR" if no operator is specified. -
defaultOperator
Returns the default operator for the query. -
flags
Specify the enabled features of the SimpleQueryString. Defaults to ALL if none are specified. -
quoteFieldSuffix
Set the suffix to append to field names for phrase matching. -
quoteFieldSuffix
Return the suffix to append to field names for phrase matching. -
lenient
Specifies whether query parsing should be lenient. Defaults to false. -
lenient
public boolean lenient()Returns whether query parsing should be lenient. -
analyzeWildcard
Specifies whether wildcards should be analyzed. Defaults to false. -
analyzeWildcard
public boolean analyzeWildcard()Returns whether wildcards should by analyzed. -
minimumShouldMatch
Specifies the minimumShouldMatch to apply to the resulting query should that be a Boolean query. -
minimumShouldMatch
Returns the minimumShouldMatch to apply to the resulting query should that be a Boolean query. -
autoGenerateSynonymsPhraseQuery
-
autoGenerateSynonymsPhraseQuery
public boolean autoGenerateSynonymsPhraseQuery()Whether phrase queries should be automatically generated for multi terms synonyms. Defaults totrue
. -
fuzzyPrefixLength
-
fuzzyPrefixLength
public int fuzzyPrefixLength() -
fuzzyMaxExpansions
-
fuzzyMaxExpansions
public int fuzzyMaxExpansions() -
fuzzyTranspositions
public boolean fuzzyTranspositions() -
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(SearchExecutionContext context) throws IOException- Specified by:
doToQuery
in classAbstractQueryBuilder<SimpleQueryStringBuilder>
- Throws:
IOException
-
doXContent
protected void doXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws IOException- Specified by:
doXContent
in classAbstractQueryBuilder<SimpleQueryStringBuilder>
- Throws:
IOException
-
fromXContent
public static SimpleQueryStringBuilder fromXContent(org.elasticsearch.common.xcontent.XContentParser parser) throws IOException- Throws:
IOException
-
getWriteableName
Description copied from interface:NamedWriteable
Returns the name of the writeable object -
doHashCode
protected int doHashCode()- Specified by:
doHashCode
in classAbstractQueryBuilder<SimpleQueryStringBuilder>
-
doEquals
Description copied from class:AbstractQueryBuilder
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.- Specified by:
doEquals
in classAbstractQueryBuilder<SimpleQueryStringBuilder>
-