public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQueryBuilder>
field(String)
, will run the query once and non prefixed fields
will use the defaultField(String)
set. The second, when one or more fields are added
(using field(String)
), will run the parsed query against the provided fields, and combine
them either using DisMax or a plain boolean query (see useDisMax(boolean)
).Writeable.Reader<V>, Writeable.Writer<V>
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Modifier and Type | Field and Description |
---|---|
static java.util.Set<java.lang.String> |
ALLOWED_QUERY_MAPPER_TYPES |
static boolean |
DEFAULT_AUTO_GENERATE_PHRASE_QUERIES |
static boolean |
DEFAULT_ENABLE_POSITION_INCREMENTS |
static boolean |
DEFAULT_ESCAPE |
static Fuzziness |
DEFAULT_FUZZINESS |
static int |
DEFAULT_FUZZY_MAX_EXPANSIONS |
static int |
DEFAULT_FUZZY_PREFIX_LENGTH |
static int |
DEFAULT_MAX_DETERMINED_STATES |
static Operator |
DEFAULT_OPERATOR |
static int |
DEFAULT_PHRASE_SLOP |
static boolean |
DEFAULT_SPLIT_ON_WHITESPACE |
static float |
DEFAULT_TIE_BREAKER |
static boolean |
DEFAULT_USE_DIS_MAX |
static java.lang.String |
NAME |
boost, BOOST_FIELD, DEFAULT_BOOST, NAME_FIELD, queryName
EMPTY_PARAMS
Constructor and Description |
---|
QueryStringQueryBuilder(StreamInput in)
Read from a stream.
|
QueryStringQueryBuilder(java.lang.String queryString) |
Modifier and Type | Method and Description |
---|---|
java.lang.Boolean |
allowLeadingWildcard() |
QueryStringQueryBuilder |
allowLeadingWildcard(java.lang.Boolean allowLeadingWildcard)
Should leading wildcards be allowed or not.
|
static java.util.Map<java.lang.String,java.lang.Float> |
allQueryableDefaultFields(QueryShardContext context)
Given a shard context, return a map of all fields in the mappings that
can be queried.
|
QueryStringQueryBuilder |
analyzer(java.lang.String analyzer)
The optional analyzer used to analyze the query string.
|
java.lang.Boolean |
analyzeWildcard() |
QueryStringQueryBuilder |
analyzeWildcard(java.lang.Boolean analyzeWildcard)
Set to true to enable analysis on wildcard and prefix queries.
|
boolean |
autoGeneratePhraseQueries() |
QueryStringQueryBuilder |
autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries)
Set to true if phrase queries will be automatically generated
when the analyzer returns more than one term from whitespace
delimited text.
|
java.lang.String |
defaultField() |
QueryStringQueryBuilder |
defaultField(java.lang.String defaultField)
The default field to run against when no prefix field is specified.
|
Operator |
defaultOperator() |
QueryStringQueryBuilder |
defaultOperator(Operator defaultOperator)
Sets the boolean operator of the query parser used to parse the query string.
|
protected boolean |
doEquals(QueryStringQueryBuilder other)
Indicates whether some other
QueryBuilder object of the same type is "equal to" this one. |
protected int |
doHashCode() |
protected org.apache.lucene.search.Query |
doToQuery(QueryShardContext context) |
protected void |
doWriteTo(StreamOutput out) |
protected void |
doXContent(XContentBuilder builder,
ToXContent.Params params) |
boolean |
enablePositionIncrements() |
QueryStringQueryBuilder |
enablePositionIncrements(boolean enablePositionIncrements)
Set to true to enable position increments in result query.
|
boolean |
escape() |
QueryStringQueryBuilder |
escape(boolean escape)
Set to true to enable escaping of the query string
|
QueryStringQueryBuilder |
field(java.lang.String field)
Adds a field to run the query string against.
|
QueryStringQueryBuilder |
field(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.
|
QueryStringQueryBuilder |
fields(java.util.Map<java.lang.String,java.lang.Float> fields)
Add several fields to run the query against with a specific boost.
|
static java.util.Optional<QueryStringQueryBuilder> |
fromXContent(QueryParseContext parseContext) |
Fuzziness |
fuzziness() |
QueryStringQueryBuilder |
fuzziness(Fuzziness fuzziness)
Set the edit distance for fuzzy queries.
|
int |
fuzzyMaxExpansions() |
QueryStringQueryBuilder |
fuzzyMaxExpansions(int fuzzyMaxExpansions) |
int |
fuzzyPrefixLength() |
QueryStringQueryBuilder |
fuzzyPrefixLength(int fuzzyPrefixLength)
Set the minimum prefix length for fuzzy queries.
|
java.lang.String |
fuzzyRewrite() |
QueryStringQueryBuilder |
fuzzyRewrite(java.lang.String fuzzyRewrite) |
java.lang.String |
getWriteableName()
Returns the name of the writeable object
|
java.lang.Boolean |
lenient() |
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.
|
int |
maxDeterminizedStates() |
QueryStringQueryBuilder |
maxDeterminizedStates(int maxDeterminizedStates)
Protects against too-difficult regular expression queries.
|
java.lang.String |
minimumShouldMatch() |
QueryStringQueryBuilder |
minimumShouldMatch(java.lang.String minimumShouldMatch) |
int |
phraseSlop() |
QueryStringQueryBuilder |
phraseSlop(int phraseSlop)
Sets the default slop for phrases.
|
java.lang.String |
queryString() |
QueryStringQueryBuilder |
quoteAnalyzer(java.lang.String quoteAnalyzer)
The optional analyzer used to analyze the query string for phrase searches.
|
java.lang.String |
quoteFieldSuffix() |
QueryStringQueryBuilder |
quoteFieldSuffix(java.lang.String quoteFieldSuffix)
An optional field name suffix to automatically try and add to the field searched when using quoted text.
|
java.lang.String |
rewrite() |
QueryStringQueryBuilder |
rewrite(java.lang.String rewrite) |
boolean |
splitOnWhitespace() |
QueryStringQueryBuilder |
splitOnWhitespace(boolean value)
Whether query text should be split on whitespace prior to analysis.
|
float |
tieBreaker() |
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.
|
org.joda.time.DateTimeZone |
timeZone() |
QueryStringQueryBuilder |
timeZone(org.joda.time.DateTimeZone timeZone) |
QueryStringQueryBuilder |
timeZone(java.lang.String timeZone)
In case of date field, we can adjust the from/to fields using a timezone
|
java.lang.Boolean |
useAllFields() |
QueryStringQueryBuilder |
useAllFields(java.lang.Boolean useAllFields)
Tell the query_string query to use all fields explicitly, even if _all is
enabled.
|
boolean |
useDisMax() |
QueryStringQueryBuilder |
useDisMax(boolean useDisMax)
When more than one field is used with the query string, should queries be combined using
dis max, or boolean query.
|
addValidationError, boost, boost, convertToBytesRefIfString, convertToStringIfBytesRef, declareStandardFields, doRewrite, equals, extractInnerHitBuilders, getName, hashCode, printBoostAndQueryName, queryName, queryName, readQueries, requireValue, rewrite, throwParsingExceptionOnMultipleFields, toFilter, toQueries, toQuery, toXContent, writeQueries, writeTo
buildAsBytes, buildAsBytes, toString, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
rewriteQuery
isFragment
public static final java.lang.String NAME
public static final boolean DEFAULT_AUTO_GENERATE_PHRASE_QUERIES
public static final int DEFAULT_MAX_DETERMINED_STATES
public static final boolean DEFAULT_ENABLE_POSITION_INCREMENTS
public static final boolean DEFAULT_ESCAPE
public static final boolean DEFAULT_USE_DIS_MAX
public static final int DEFAULT_FUZZY_PREFIX_LENGTH
public static final int DEFAULT_FUZZY_MAX_EXPANSIONS
public static final int DEFAULT_PHRASE_SLOP
public static final float DEFAULT_TIE_BREAKER
public static final Fuzziness DEFAULT_FUZZINESS
public static final Operator DEFAULT_OPERATOR
public static final boolean DEFAULT_SPLIT_ON_WHITESPACE
public static final java.util.Set<java.lang.String> ALLOWED_QUERY_MAPPER_TYPES
public QueryStringQueryBuilder(java.lang.String queryString)
public QueryStringQueryBuilder(StreamInput in) throws java.io.IOException
java.io.IOException
protected void doWriteTo(StreamOutput out) throws java.io.IOException
doWriteTo
in class AbstractQueryBuilder<QueryStringQueryBuilder>
java.io.IOException
public java.lang.String queryString()
public QueryStringQueryBuilder defaultField(java.lang.String defaultField)
public java.lang.String defaultField()
public QueryStringQueryBuilder useAllFields(java.lang.Boolean useAllFields)
public java.lang.Boolean useAllFields()
public QueryStringQueryBuilder field(java.lang.String field)
AbstractQueryBuilder.DEFAULT_BOOST
.
Use field(String, float)
to set a specific boost for the field.public QueryStringQueryBuilder field(java.lang.String field, float boost)
public QueryStringQueryBuilder fields(java.util.Map<java.lang.String,java.lang.Float> fields)
public java.util.Map<java.lang.String,java.lang.Float> fields()
public QueryStringQueryBuilder useDisMax(boolean useDisMax)
public boolean useDisMax()
public QueryStringQueryBuilder tieBreaker(float tieBreaker)
public float tieBreaker()
public QueryStringQueryBuilder defaultOperator(Operator defaultOperator)
In default mode (Operator.OR
) terms without any modifiers
are considered optional: for example capital of Hungary
is equal to
capital OR of OR Hungary
.
In Operator.AND
mode terms are considered to be in conjunction: the
above mentioned query is parsed as capital AND of AND Hungary
public Operator defaultOperator()
public QueryStringQueryBuilder analyzer(java.lang.String analyzer)
public QueryStringQueryBuilder quoteAnalyzer(java.lang.String quoteAnalyzer)
public QueryStringQueryBuilder autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries)
Set to false if phrase queries should only be generated when surrounded by double quotes.
public boolean autoGeneratePhraseQueries()
public QueryStringQueryBuilder maxDeterminizedStates(int maxDeterminizedStates)
public int maxDeterminizedStates()
public QueryStringQueryBuilder allowLeadingWildcard(java.lang.Boolean allowLeadingWildcard)
public java.lang.Boolean allowLeadingWildcard()
public QueryStringQueryBuilder enablePositionIncrements(boolean enablePositionIncrements)
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.
public boolean enablePositionIncrements()
public QueryStringQueryBuilder fuzziness(Fuzziness fuzziness)
public Fuzziness fuzziness()
public QueryStringQueryBuilder fuzzyPrefixLength(int fuzzyPrefixLength)
public int fuzzyPrefixLength()
public QueryStringQueryBuilder fuzzyMaxExpansions(int fuzzyMaxExpansions)
public int fuzzyMaxExpansions()
public QueryStringQueryBuilder fuzzyRewrite(java.lang.String fuzzyRewrite)
public java.lang.String fuzzyRewrite()
public QueryStringQueryBuilder phraseSlop(int phraseSlop)
public int phraseSlop()
public QueryStringQueryBuilder rewrite(java.lang.String rewrite)
public QueryStringQueryBuilder analyzeWildcard(java.lang.Boolean analyzeWildcard)
public java.lang.Boolean analyzeWildcard()
public java.lang.String rewrite()
public QueryStringQueryBuilder minimumShouldMatch(java.lang.String minimumShouldMatch)
public java.lang.String minimumShouldMatch()
public QueryStringQueryBuilder quoteFieldSuffix(java.lang.String quoteFieldSuffix)
public java.lang.String quoteFieldSuffix()
public QueryStringQueryBuilder lenient(java.lang.Boolean lenient)
public java.lang.Boolean lenient()
public QueryStringQueryBuilder timeZone(java.lang.String timeZone)
public QueryStringQueryBuilder timeZone(org.joda.time.DateTimeZone timeZone)
public org.joda.time.DateTimeZone timeZone()
public QueryStringQueryBuilder escape(boolean escape)
public boolean escape()
public QueryStringQueryBuilder splitOnWhitespace(boolean value)
true
.public boolean splitOnWhitespace()
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
doXContent
in class AbstractQueryBuilder<QueryStringQueryBuilder>
java.io.IOException
public static java.util.Optional<QueryStringQueryBuilder> fromXContent(QueryParseContext parseContext) throws java.io.IOException
java.io.IOException
public java.lang.String getWriteableName()
NamedWriteable
protected boolean doEquals(QueryStringQueryBuilder other)
AbstractQueryBuilder
QueryBuilder
object of the same type is "equal to" this one.doEquals
in class AbstractQueryBuilder<QueryStringQueryBuilder>
protected int doHashCode()
doHashCode
in class AbstractQueryBuilder<QueryStringQueryBuilder>
public static java.util.Map<java.lang.String,java.lang.Float> allQueryableDefaultFields(QueryShardContext context)
protected org.apache.lucene.search.Query doToQuery(QueryShardContext context) throws java.io.IOException
doToQuery
in class AbstractQueryBuilder<QueryStringQueryBuilder>
java.io.IOException