java.lang.Object
org.elasticsearch.index.query.AbstractQueryBuilder<BoolQueryBuilder>
org.elasticsearch.index.query.BoolQueryBuilder
- All Implemented Interfaces:
NamedWriteable,VersionedNamedWriteable,Writeable,QueryBuilder,Rewriteable<QueryBuilder>,ToXContent,ToXContentObject
A Query that matches documents matching boolean combinations of other queries.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.ParamsNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsFields inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
boost, BOOST_FIELD, DEFAULT_BOOST, NAME_FIELD, queryNameFields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDSFields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionBuild an empty bool query.Read from a stream. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadjustPureNegative(boolean adjustPureNegative) If a boolean query contains only negative ("must not") clauses should the BooleanQuery be enhanced with aMatchAllDocsQueryin order to act as a pure exclude.protected booleandoEquals(BoolQueryBuilder other) Indicates whether some otherQueryBuilderobject of the same type is "equal to" this one.protected intprotected QueryBuilderdoRewrite(QueryRewriteContext queryRewriteContext) protected org.apache.lucene.search.QuerydoToQuery(SearchExecutionContext context) protected voiddoWriteTo(StreamOutput out) protected voiddoXContent(XContentBuilder builder, ToXContent.Params params) protected voidextractInnerHitBuilders(Map<String, InnerHitContextBuilder> innerHits) For internal usage only! Extracts the inner hits from the query tree.filter()Gets the queries that must appear in the matching documents but don't contribute to scoringfilter(QueryBuilder queryBuilder) Adds a query that must appear in the matching documents but will not contribute to scoring.static BoolQueryBuilderfromXContent(XContentParser parser, Integer nestedDepth) The minimal version of the recipient this object can be sent toReturns the name of the writeable objectbooleanReturnstrueiff this query builder has at least one should, must, must not or filter clause.minimumShouldMatch(int minimumShouldMatch) Specifies a minimum number of the optional (should) boolean clauses which must be satisfied.minimumShouldMatch(String minimumShouldMatch) Sets the minimum should match parameter using the special syntax (for example, supporting percentage).must()Gets the queries that must appear in the matching documents.must(QueryBuilder queryBuilder) Adds a query that must appear in the matching documents and will contribute to scoring.mustNot()Gets the queries that must not appear in the matching documents.mustNot(QueryBuilder queryBuilder) Adds a query that must not appear in the matching documents.static voidsetMaxNestedDepth(int maxNestedDepth) Set the maximum nested depth of bool queries.should()Gets the list of clauses that should be matched by the returned documents.should(QueryBuilder queryBuilder) Adds a clause that should be matched by the returned documents.Methods inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
addValidationError, boost, boost, boostAndQueryNameToXContent, checkNegativeBoost, declareStandardFields, equals, getName, hashCode, parseInnerQueryBuilder, parseInnerQueryBuilder, printBoostAndQueryName, queryName, queryName, readQueries, requireValue, rewrite, throwParsingExceptionOnMultipleFields, toQuery, toString, toXContent, writeQueries, writeToMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.xcontent.ToXContentObject
isFragment
-
Field Details
-
NAME
- See Also:
-
ADJUST_PURE_NEGATIVE_DEFAULT
public static final boolean ADJUST_PURE_NEGATIVE_DEFAULT- See Also:
-
-
Constructor Details
-
BoolQueryBuilder
public BoolQueryBuilder()Build an empty bool query. -
BoolQueryBuilder
Read from a stream.- Throws:
IOException
-
-
Method Details
-
setMaxNestedDepth
public static void setMaxNestedDepth(int maxNestedDepth) Set the maximum nested depth of bool queries. Default value is 20. -
doWriteTo
- Specified by:
doWriteToin classAbstractQueryBuilder<BoolQueryBuilder>- Throws:
IOException
-
must
Adds a query that must appear in the matching documents and will contribute to scoring. Nonullvalue allowed. -
must
Gets the queries that must appear in the matching documents. -
filter
Adds a query that must appear in the matching documents but will not contribute to scoring. Nonullvalue allowed. -
filter
Gets the queries that must appear in the matching documents but don't contribute to scoring -
mustNot
Adds a query that must not appear in the matching documents. Nonullvalue allowed. -
mustNot
Gets the queries that must not appear in the matching documents. -
should
Adds a clause that should be matched by the returned documents. For a boolean query with noMUSTclauses one or moreSHOULDclauses must match a document for the BooleanQuery to match. Nonullvalue allowed.- See Also:
-
should
Gets the list of clauses that should be matched by the returned documents.- See Also:
-
minimumShouldMatch
- Returns:
- the string representation of the minimumShouldMatch settings for this query
-
minimumShouldMatch
Sets the minimum should match parameter using the special syntax (for example, supporting percentage).- See Also:
-
minimumShouldMatch
Specifies a minimum number of the optional (should) boolean clauses which must be satisfied.By default no optional clauses are necessary for a match (unless there are no required clauses). If this method is used, then the specified number of clauses is required.
Use of this method is totally independent of specifying that any specific clauses are required (or prohibited). This number will only be compared against the number of matching optional clauses.
- Parameters:
minimumShouldMatch- the number of optional clauses that must match
-
hasClauses
public boolean hasClauses()Returnstrueiff this query builder has at least one should, must, must not or filter clause. Otherwisefalse. -
adjustPureNegative
If a boolean query contains only negative ("must not") clauses should the BooleanQuery be enhanced with aMatchAllDocsQueryin order to act as a pure exclude. The default istrue. -
adjustPureNegative
public boolean adjustPureNegative()- Returns:
- the setting for the adjust_pure_negative setting in this query
-
doXContent
- Specified by:
doXContentin classAbstractQueryBuilder<BoolQueryBuilder>- Throws:
IOException
-
fromXContent
public static BoolQueryBuilder fromXContent(XContentParser parser, Integer nestedDepth) throws IOException, ParsingException - Throws:
IOExceptionParsingException
-
getWriteableName
Description copied from interface:VersionedNamedWriteableReturns the name of the writeable object -
doToQuery
protected org.apache.lucene.search.Query doToQuery(SearchExecutionContext context) throws IOException - Specified by:
doToQueryin classAbstractQueryBuilder<BoolQueryBuilder>- Throws:
IOException
-
doHashCode
protected int doHashCode()- Specified by:
doHashCodein classAbstractQueryBuilder<BoolQueryBuilder>
-
doEquals
Description copied from class:AbstractQueryBuilderIndicates whether some otherQueryBuilderobject of the same type is "equal to" this one.- Specified by:
doEqualsin classAbstractQueryBuilder<BoolQueryBuilder>
-
doRewrite
- Overrides:
doRewritein classAbstractQueryBuilder<BoolQueryBuilder>- Throws:
IOException
-
extractInnerHitBuilders
Description copied from class:AbstractQueryBuilderFor 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.- Overrides:
extractInnerHitBuildersin classAbstractQueryBuilder<BoolQueryBuilder>
-
getMinimalSupportedVersion
Description copied from interface:VersionedNamedWriteableThe minimal version of the recipient this object can be sent to
-