Class QueryStringQueryBuilder
- java.lang.Object
-
- org.elasticsearch.index.query.AbstractQueryBuilder<QueryStringQueryBuilder>
-
- org.elasticsearch.index.query.QueryStringQueryBuilder
-
- All Implemented Interfaces:
NamedWriteable,Writeable,ToXContent,ToXContentObject,QueryBuilder,Rewriteable<QueryBuilder>
public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQueryBuilder>
A query that parses a query string and runs it. There are two modes that this operates. The first, when no field is added (usingfield(String), will run the query once and non prefixed fields will use thedefaultField(String)set. The second, when one or more fields are added (usingfield(String)), will run the parsed query against the provided fields, and combine them using Dismax.
-
-
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_ENABLE_POSITION_INCREMENTSstatic booleanDEFAULT_ESCAPEstatic FuzzinessDEFAULT_FUZZINESSstatic intDEFAULT_FUZZY_MAX_EXPANSIONSstatic intDEFAULT_FUZZY_PREFIX_LENGTHstatic booleanDEFAULT_FUZZY_TRANSPOSITIONSstatic intDEFAULT_MAX_DETERMINED_STATESstatic OperatorDEFAULT_OPERATORstatic intDEFAULT_PHRASE_SLOPstatic MultiMatchQueryBuilder.TypeDEFAULT_TYPEstatic java.lang.StringNAME-
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 QueryStringQueryBuilder(java.lang.String queryString)QueryStringQueryBuilder(StreamInput in)Read from a stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.BooleanallowLeadingWildcard()QueryStringQueryBuilderallowLeadingWildcard(java.lang.Boolean allowLeadingWildcard)Should leading wildcards be allowed or not.java.lang.Stringanalyzer()The optional analyzer used to analyze the query string.QueryStringQueryBuilderanalyzer(java.lang.String analyzer)The optional analyzer used to analyze the query string.java.lang.BooleananalyzeWildcard()QueryStringQueryBuilderanalyzeWildcard(java.lang.Boolean analyzeWildcard)Set totrueto enable analysis on wildcard and prefix queries.booleanautoGeneratePhraseQueries()Deprecated.QueryStringQueryBuilderautoGeneratePhraseQueries(boolean autoGeneratePhraseQueries)Deprecated.booleanautoGenerateSynonymsPhraseQuery()Whether phrase queries should be automatically generated for multi terms synonyms.QueryStringQueryBuilderautoGenerateSynonymsPhraseQuery(boolean value)java.lang.StringdefaultField()QueryStringQueryBuilderdefaultField(java.lang.String defaultField)The default field to run against when no prefix field is specified.OperatordefaultOperator()QueryStringQueryBuilderdefaultOperator(Operator defaultOperator)Sets the boolean operator of the query parser used to parse the query string.protected booleandoEquals(QueryStringQueryBuilder 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)booleanenablePositionIncrements()QueryStringQueryBuilderenablePositionIncrements(boolean enablePositionIncrements)Set totrueto enable position increments in result query.booleanescape()QueryStringQueryBuilderescape(boolean escape)Set totrueto enable escaping of the query stringQueryStringQueryBuilderfield(java.lang.String field)Adds a field to run the query string against.QueryStringQueryBuilderfield(java.lang.String field, float boost)Adds a field to run the query string 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.QueryStringQueryBuilderfields(java.util.Map<java.lang.String,java.lang.Float> fields)Add several fields to run the query against with a specific boost.static QueryStringQueryBuilderfromXContent(XContentParser parser)Fuzzinessfuzziness()QueryStringQueryBuilderfuzziness(Fuzziness fuzziness)Set the edit distance for fuzzy queries.intfuzzyMaxExpansions()QueryStringQueryBuilderfuzzyMaxExpansions(int fuzzyMaxExpansions)intfuzzyPrefixLength()QueryStringQueryBuilderfuzzyPrefixLength(int fuzzyPrefixLength)Set the minimum prefix length for fuzzy queries.java.lang.StringfuzzyRewrite()QueryStringQueryBuilderfuzzyRewrite(java.lang.String fuzzyRewrite)booleanfuzzyTranspositions()QueryStringQueryBuilderfuzzyTranspositions(boolean fuzzyTranspositions)Sets whether transpositions are supported in fuzzy queries.java.lang.StringgetWriteableName()Returns the name of the writeable objectjava.lang.Booleanlenient()QueryStringQueryBuilderlenient(java.lang.Boolean lenient)Sets the query string parser to be lenient when parsing field values, defaults to the index setting and if not set, defaults to false.intmaxDeterminizedStates()QueryStringQueryBuildermaxDeterminizedStates(int maxDeterminizedStates)Protects against too-difficult regular expression queries.java.lang.StringminimumShouldMatch()QueryStringQueryBuilderminimumShouldMatch(java.lang.String minimumShouldMatch)intphraseSlop()QueryStringQueryBuilderphraseSlop(int phraseSlop)Sets the default slop for phrases.java.lang.StringqueryString()java.lang.StringquoteAnalyzer()The optional analyzer used to analyze the query string for phrase searches.QueryStringQueryBuilderquoteAnalyzer(java.lang.String quoteAnalyzer)The optional analyzer used to analyze the query string for phrase searches.java.lang.StringquoteFieldSuffix()QueryStringQueryBuilderquoteFieldSuffix(java.lang.String quoteFieldSuffix)An optional field name suffix to automatically try and add to the field searched when using quoted text.java.lang.Stringrewrite()QueryStringQueryBuilderrewrite(java.lang.String rewrite)booleansplitOnWhitespace()Deprecated.QueryStringQueryBuildersplitOnWhitespace(boolean value)Deprecated.java.lang.FloattieBreaker()QueryStringQueryBuildertieBreaker(float tieBreaker)When more than one field is used with the query string, and combined queries are using dis max, control the tie breaker for it.org.joda.time.DateTimeZonetimeZone()QueryStringQueryBuildertimeZone(java.lang.String timeZone)In case of date field, we can adjust the from/to fields using a timezoneQueryStringQueryBuildertimeZone(org.joda.time.DateTimeZone timeZone)QueryStringQueryBuildertype(MultiMatchQueryBuilder.Type type)java.lang.BooleanuseAllFields()Deprecated.QueryStringQueryBuilderuseAllFields(java.lang.Boolean useAllFields)Deprecated.booleanuseDisMax()Deprecated.QueryStringQueryBuilderuseDisMax(boolean useDisMax)Deprecated.-
Methods inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
addValidationError, boost, boost, declareStandardFields, doRewrite, equals, extractInnerHitBuilders, getName, hashCode, parseInnerQueryBuilder, printBoostAndQueryName, queryName, queryName, requireValue, rewrite, throwParsingExceptionOnMultipleFields, toFilter, 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.index.query.Rewriteable
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
DEFAULT_MAX_DETERMINED_STATES
public static final int DEFAULT_MAX_DETERMINED_STATES
- See Also:
- Constant Field Values
-
DEFAULT_ENABLE_POSITION_INCREMENTS
public static final boolean DEFAULT_ENABLE_POSITION_INCREMENTS
- See Also:
- Constant Field Values
-
DEFAULT_ESCAPE
public static final boolean DEFAULT_ESCAPE
- See Also:
- Constant Field Values
-
DEFAULT_FUZZY_PREFIX_LENGTH
public static final int DEFAULT_FUZZY_PREFIX_LENGTH
- See Also:
- Constant Field Values
-
DEFAULT_FUZZY_MAX_EXPANSIONS
public static final int DEFAULT_FUZZY_MAX_EXPANSIONS
- See Also:
- Constant Field Values
-
DEFAULT_PHRASE_SLOP
public static final int DEFAULT_PHRASE_SLOP
- See Also:
- Constant Field Values
-
DEFAULT_FUZZINESS
public static final Fuzziness DEFAULT_FUZZINESS
-
DEFAULT_OPERATOR
public static final Operator DEFAULT_OPERATOR
-
DEFAULT_TYPE
public static final MultiMatchQueryBuilder.Type DEFAULT_TYPE
-
DEFAULT_FUZZY_TRANSPOSITIONS
public static final boolean DEFAULT_FUZZY_TRANSPOSITIONS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
QueryStringQueryBuilder
public QueryStringQueryBuilder(java.lang.String queryString)
-
QueryStringQueryBuilder
public QueryStringQueryBuilder(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<QueryStringQueryBuilder>- Throws:
java.io.IOException
-
queryString
public java.lang.String queryString()
-
defaultField
public QueryStringQueryBuilder defaultField(java.lang.String defaultField)
The default field to run against when no prefix field is specified. Only relevant when not explicitly adding fields the query string will run against.
-
defaultField
public java.lang.String defaultField()
-
useAllFields
@Deprecated public QueryStringQueryBuilder useAllFields(java.lang.Boolean useAllFields)
Deprecated.This setting is deprecated, setdefaultField(String)to "*" instead.
-
useAllFields
@Deprecated public java.lang.Boolean useAllFields()
Deprecated.
-
field
public QueryStringQueryBuilder field(java.lang.String field)
Adds a field to run the query string against. The field will be associated with the default boost ofAbstractQueryBuilder.DEFAULT_BOOST. Usefield(String, float)to set a specific boost for the field.
-
field
public QueryStringQueryBuilder field(java.lang.String field, float boost)
Adds a field to run the query string against with a specific boost.
-
fields
public QueryStringQueryBuilder 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.
-
type
public QueryStringQueryBuilder type(MultiMatchQueryBuilder.Type type)
- Parameters:
type- Sets how multiple fields should be combined to build textual part queries.
-
useDisMax
@Deprecated public QueryStringQueryBuilder useDisMax(boolean useDisMax)
Deprecated.UsetieBreakerinstead.
-
useDisMax
@Deprecated public boolean useDisMax()
Deprecated.UsetieBreakerinstead.
-
tieBreaker
public QueryStringQueryBuilder tieBreaker(float tieBreaker)
When more than one field is used with the query string, and combined queries are using dis max, control the tie breaker for it.
-
tieBreaker
public java.lang.Float tieBreaker()
-
defaultOperator
public QueryStringQueryBuilder defaultOperator(Operator defaultOperator)
Sets the boolean operator of the query parser used to parse the query string.In default mode (
Operator.OR) terms without any modifiers are considered optional: for examplecapital of Hungaryis equal tocapital OR of OR Hungary.In
Operator.ANDmode terms are considered to be in conjunction: the above mentioned query is parsed ascapital AND of AND Hungary
-
defaultOperator
public Operator defaultOperator()
-
analyzer
public QueryStringQueryBuilder analyzer(java.lang.String analyzer)
The optional analyzer used to analyze the query string. Note, if a field has search analyzer defined for it, then it will be used automatically. Defaults to the smart search analyzer.
-
analyzer
public java.lang.String analyzer()
The optional analyzer used to analyze the query string. Note, if a field has search analyzer defined for it, then it will be used automatically. Defaults to the smart search analyzer.
-
quoteAnalyzer
public java.lang.String quoteAnalyzer()
The optional analyzer used to analyze the query string for phrase searches. Note, if a field has search (quote) analyzer defined for it, then it will be used automatically. Defaults to the smart search analyzer.
-
quoteAnalyzer
public QueryStringQueryBuilder quoteAnalyzer(java.lang.String quoteAnalyzer)
The optional analyzer used to analyze the query string for phrase searches. Note, if a field has search (quote) analyzer defined for it, then it will be used automatically. Defaults to the smart search analyzer.
-
autoGeneratePhraseQueries
@Deprecated public QueryStringQueryBuilder autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries)
Deprecated.This setting is ignored
-
autoGeneratePhraseQueries
@Deprecated public boolean autoGeneratePhraseQueries()
Deprecated.This setting is ignored
-
maxDeterminizedStates
public QueryStringQueryBuilder maxDeterminizedStates(int maxDeterminizedStates)
Protects against too-difficult regular expression queries.
-
maxDeterminizedStates
public int maxDeterminizedStates()
-
allowLeadingWildcard
public QueryStringQueryBuilder allowLeadingWildcard(java.lang.Boolean allowLeadingWildcard)
Should leading wildcards be allowed or not. Defaults totrue.
-
allowLeadingWildcard
public java.lang.Boolean allowLeadingWildcard()
-
enablePositionIncrements
public QueryStringQueryBuilder enablePositionIncrements(boolean enablePositionIncrements)
Set totrueto enable position increments in result query. Defaults totrue.When set, result phrase and multi-phrase queries will be aware of position increments. Useful when e.g. a StopFilter increases the position increment of the token that follows an omitted token.
-
enablePositionIncrements
public boolean enablePositionIncrements()
-
fuzziness
public QueryStringQueryBuilder fuzziness(Fuzziness fuzziness)
Set the edit distance for fuzzy queries. Default is "AUTO".
-
fuzziness
public Fuzziness fuzziness()
-
fuzzyPrefixLength
public QueryStringQueryBuilder fuzzyPrefixLength(int fuzzyPrefixLength)
Set the minimum prefix length for fuzzy queries. Default is 1.
-
fuzzyPrefixLength
public int fuzzyPrefixLength()
-
fuzzyMaxExpansions
public QueryStringQueryBuilder fuzzyMaxExpansions(int fuzzyMaxExpansions)
-
fuzzyMaxExpansions
public int fuzzyMaxExpansions()
-
fuzzyRewrite
public QueryStringQueryBuilder fuzzyRewrite(java.lang.String fuzzyRewrite)
-
fuzzyRewrite
public java.lang.String fuzzyRewrite()
-
phraseSlop
public QueryStringQueryBuilder phraseSlop(int phraseSlop)
Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
-
phraseSlop
public int phraseSlop()
-
rewrite
public QueryStringQueryBuilder rewrite(java.lang.String rewrite)
-
analyzeWildcard
public QueryStringQueryBuilder analyzeWildcard(java.lang.Boolean analyzeWildcard)
Set totrueto enable analysis on wildcard and prefix queries.
-
analyzeWildcard
public java.lang.Boolean analyzeWildcard()
-
rewrite
public java.lang.String rewrite()
-
minimumShouldMatch
public QueryStringQueryBuilder minimumShouldMatch(java.lang.String minimumShouldMatch)
-
minimumShouldMatch
public java.lang.String minimumShouldMatch()
-
quoteFieldSuffix
public QueryStringQueryBuilder quoteFieldSuffix(java.lang.String quoteFieldSuffix)
An optional field name suffix to automatically try and add to the field searched when using quoted text.
-
quoteFieldSuffix
public java.lang.String quoteFieldSuffix()
-
lenient
public QueryStringQueryBuilder lenient(java.lang.Boolean lenient)
Sets the query string parser to be lenient when parsing field values, defaults to the index setting and if not set, defaults to false.
-
lenient
public java.lang.Boolean lenient()
-
timeZone
public QueryStringQueryBuilder timeZone(java.lang.String timeZone)
In case of date field, we can adjust the from/to fields using a timezone
-
timeZone
public QueryStringQueryBuilder timeZone(org.joda.time.DateTimeZone timeZone)
-
timeZone
public org.joda.time.DateTimeZone timeZone()
-
escape
public QueryStringQueryBuilder escape(boolean escape)
Set totrueto enable escaping of the query string
-
escape
public boolean escape()
-
splitOnWhitespace
@Deprecated public QueryStringQueryBuilder splitOnWhitespace(boolean value)
Deprecated.This setting is ignored, this query parser splits on operator only.
-
splitOnWhitespace
@Deprecated public boolean splitOnWhitespace()
Deprecated.This setting is ignored, this query parser splits on operator only.
-
autoGenerateSynonymsPhraseQuery
public QueryStringQueryBuilder autoGenerateSynonymsPhraseQuery(boolean value)
-
autoGenerateSynonymsPhraseQuery
public boolean autoGenerateSynonymsPhraseQuery()
Whether phrase queries should be automatically generated for multi terms synonyms. Defaults totrue.
-
fuzzyTranspositions
public boolean fuzzyTranspositions()
-
fuzzyTranspositions
public QueryStringQueryBuilder 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
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
doXContentin classAbstractQueryBuilder<QueryStringQueryBuilder>- Throws:
java.io.IOException
-
fromXContent
public static QueryStringQueryBuilder 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
-
doEquals
protected boolean doEquals(QueryStringQueryBuilder other)
Description copied from class:AbstractQueryBuilderIndicates whether some otherQueryBuilderobject of the same type is "equal to" this one.- Specified by:
doEqualsin classAbstractQueryBuilder<QueryStringQueryBuilder>
-
doHashCode
protected int doHashCode()
- Specified by:
doHashCodein classAbstractQueryBuilder<QueryStringQueryBuilder>
-
doToQuery
protected org.apache.lucene.search.Query doToQuery(QueryShardContext context) throws java.io.IOException
- Specified by:
doToQueryin classAbstractQueryBuilder<QueryStringQueryBuilder>- Throws:
java.io.IOException
-
-