Package org.elasticsearch.index.query
Class AbstractQueryBuilder<QB extends AbstractQueryBuilder<QB>>
java.lang.Object
org.elasticsearch.index.query.AbstractQueryBuilder<QB>
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentObject
,QueryBuilder
,Rewriteable<QueryBuilder>
- Direct Known Subclasses:
AbstractGeometryQueryBuilder
,BaseTermQueryBuilder
,BoolQueryBuilder
,BoostingQueryBuilder
,CommonTermsQueryBuilder
,ConstantScoreQueryBuilder
,DisMaxQueryBuilder
,DistanceFeatureQueryBuilder
,ExistsQueryBuilder
,FieldMaskingSpanQueryBuilder
,FunctionScoreQueryBuilder
,FuzzyQueryBuilder
,GeoBoundingBoxQueryBuilder
,GeoDistanceQueryBuilder
,GeoPolygonQueryBuilder
,IdsQueryBuilder
,IntervalQueryBuilder
,MatchAllQueryBuilder
,MatchBoolPrefixQueryBuilder
,MatchNoneQueryBuilder
,MatchPhrasePrefixQueryBuilder
,MatchPhraseQueryBuilder
,MatchQueryBuilder
,MoreLikeThisQueryBuilder
,MultiMatchQueryBuilder
,NestedQueryBuilder
,PrefixQueryBuilder
,QueryStringQueryBuilder
,RangeQueryBuilder
,RegexpQueryBuilder
,ScriptQueryBuilder
,ScriptScoreQueryBuilder
,SimpleQueryStringBuilder
,SpanContainingQueryBuilder
,SpanFirstQueryBuilder
,SpanMultiTermQueryBuilder
,SpanNearQueryBuilder
,SpanNotQueryBuilder
,SpanOrQueryBuilder
,SpanWithinQueryBuilder
,TermsQueryBuilder
,TermsSetQueryBuilder
,TypeQueryBuilder
,WildcardQueryBuilder
,WrapperQueryBuilder
public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder<QB>> extends java.lang.Object implements QueryBuilder
Base class for all classes producing lucene queries.
Supports conversion to BytesReference and creation of lucene Query objects.
-
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 protected float
boost
static ParseField
BOOST_FIELD
static float
DEFAULT_BOOST
Default for boost to apply to resulting Lucene query.static ParseField
NAME_FIELD
protected java.lang.String
queryName
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractQueryBuilder()
protected
AbstractQueryBuilder(StreamInput in)
-
Method Summary
Modifier and Type Method Description protected QueryValidationException
addValidationError(java.lang.String validationError, QueryValidationException validationException)
float
boost()
Returns the boost for this query.QB
boost(float boost)
Sets the boost for this query.protected void
checkNegativeBoost(float boost)
protected static void
declareStandardFields(AbstractObjectParser<? extends QueryBuilder,?> parser)
protected abstract boolean
doEquals(QB other)
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.protected abstract int
doHashCode()
protected QueryBuilder
doRewrite(QueryRewriteContext queryShardContext)
protected abstract org.apache.lucene.search.Query
doToQuery(QueryShardContext context)
protected abstract void
doWriteTo(StreamOutput out)
protected abstract void
doXContent(XContentBuilder builder, ToXContent.Params params)
boolean
equals(java.lang.Object obj)
protected void
extractInnerHitBuilders(java.util.Map<java.lang.String,InnerHitContextBuilder> innerHits)
For internal usage only! Extracts the inner hits from the query tree.java.lang.String
getName()
Returns the name that identifies uniquely the queryint
hashCode()
static QueryBuilder
parseInnerQueryBuilder(XContentParser parser)
Parses a query excluding the query element that wraps itprotected void
printBoostAndQueryName(XContentBuilder builder)
java.lang.String
queryName()
Returns the query name for the query.QB
queryName(java.lang.String queryName)
Sets the query name for the query.protected static <T> T
requireValue(T value, java.lang.String message)
QueryBuilder
rewrite(QueryRewriteContext queryShardContext)
Rewrites this query builder into its primitive form.protected static void
throwParsingExceptionOnMultipleFields(java.lang.String queryName, XContentLocation contentLocation, java.lang.String processedFieldName, java.lang.String currentFieldName)
org.apache.lucene.search.Query
toQuery(QueryShardContext context)
Converts this QueryBuilder to a luceneQuery
.java.lang.String
toString()
XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
void
writeTo(StreamOutput out)
Write this into the StreamOutput.
-
Field Details
-
DEFAULT_BOOST
public static final float DEFAULT_BOOSTDefault for boost to apply to resulting Lucene query. Defaults to 1.0- See Also:
- Constant Field Values
-
NAME_FIELD
-
BOOST_FIELD
-
queryName
protected java.lang.String queryName -
boost
protected float boost
-
-
Constructor Details
-
AbstractQueryBuilder
protected AbstractQueryBuilder() -
AbstractQueryBuilder
- Throws:
java.io.IOException
-
-
Method Details
-
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput. -
doWriteTo
- Throws:
java.io.IOException
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException- Specified by:
toXContent
in interfaceToXContent
- Throws:
java.io.IOException
-
doXContent
protected abstract void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException- Throws:
java.io.IOException
-
printBoostAndQueryName
- Throws:
java.io.IOException
-
toQuery
public final org.apache.lucene.search.Query toQuery(QueryShardContext context) throws java.io.IOExceptionDescription copied from interface:QueryBuilder
Converts this QueryBuilder to a luceneQuery
. Returnsnull
if this query should be ignored in the context of parent queries.- Specified by:
toQuery
in interfaceQueryBuilder
- Parameters:
context
- additional information needed to construct the queries- Returns:
- the
Query
ornull
if this query should be ignored upstream - Throws:
java.io.IOException
-
doToQuery
protected abstract org.apache.lucene.search.Query doToQuery(QueryShardContext context) throws java.io.IOException- Throws:
java.io.IOException
-
queryName
Sets the query name for the query.- Specified by:
queryName
in interfaceQueryBuilder
-
queryName
public final java.lang.String queryName()Returns the query name for the query.- Specified by:
queryName
in interfaceQueryBuilder
-
boost
public final float boost()Returns the boost for this query.- Specified by:
boost
in interfaceQueryBuilder
-
checkNegativeBoost
protected final void checkNegativeBoost(float boost) -
boost
Sets the boost for this query. Documents matching this query will (in addition to the normal weightings) have their score multiplied by the boost provided.- Specified by:
boost
in interfaceQueryBuilder
-
addValidationError
protected final QueryValidationException addValidationError(java.lang.String validationError, QueryValidationException validationException) -
equals
public final boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
doEquals
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one. -
hashCode
public final int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
doHashCode
protected abstract int doHashCode() -
getName
public java.lang.String getName()Description copied from interface:QueryBuilder
Returns the name that identifies uniquely the query- Specified by:
getName
in interfaceQueryBuilder
-
rewrite
public final QueryBuilder rewrite(QueryRewriteContext queryShardContext) throws java.io.IOExceptionDescription copied from interface:QueryBuilder
Rewrites this query builder into its primitive form. By default this method return the builder itself. If the builder did not change the identity reference must be returned otherwise the builder will be rewritten infinitely.- Specified by:
rewrite
in interfaceQueryBuilder
- Specified by:
rewrite
in interfaceRewriteable<QB extends AbstractQueryBuilder<QB>>
- Throws:
java.io.IOException
-
doRewrite
- Throws:
java.io.IOException
-
extractInnerHitBuilders
protected void extractInnerHitBuilders(java.util.Map<java.lang.String,InnerHitContextBuilder> innerHits)For internal usage only! Extracts the inner hits from the query tree. While it extracts inner hits, child inner hits are inlined into the inner hit builder they belong to. -
parseInnerQueryBuilder
public static QueryBuilder parseInnerQueryBuilder(XContentParser parser) throws java.io.IOExceptionParses a query excluding the query element that wraps it- Throws:
java.io.IOException
-
requireValue
protected static <T> T requireValue(T value, java.lang.String message) -
throwParsingExceptionOnMultipleFields
protected static void throwParsingExceptionOnMultipleFields(java.lang.String queryName, XContentLocation contentLocation, java.lang.String processedFieldName, java.lang.String currentFieldName) -
declareStandardFields
protected static void declareStandardFields(AbstractObjectParser<? extends QueryBuilder,?> parser)Addsboost
andquery_name
parsing to theAbstractObjectParser
passed in. All query builders exceptMatchAllQueryBuilder
andMatchNoneQueryBuilder
support these fields so they should use this method. -
toString
public final java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-