public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder>
Writeable.Reader<V>, Writeable.Writer<V>
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Modifier and Type | Field and Description |
---|---|
static boolean |
ADJUST_PURE_NEGATIVE_DEFAULT |
static java.lang.String |
NAME |
boost, BOOST_FIELD, DEFAULT_BOOST, NAME_FIELD, queryName
EMPTY_PARAMS
Constructor and Description |
---|
BoolQueryBuilder()
Build an empty bool query.
|
BoolQueryBuilder(StreamInput in)
Read from a stream.
|
Modifier and Type | Method and Description |
---|---|
boolean |
adjustPureNegative() |
BoolQueryBuilder |
adjustPureNegative(boolean adjustPureNegative)
If a boolean query contains only negative ("must not") clauses should the
BooleanQuery be enhanced with a
MatchAllDocsQuery in order to act
as a pure exclude. |
protected boolean |
doEquals(BoolQueryBuilder other)
Indicates whether some other
QueryBuilder object of the same type is "equal to" this one. |
protected int |
doHashCode() |
protected QueryBuilder |
doRewrite(QueryRewriteContext queryRewriteContext) |
protected org.apache.lucene.search.Query |
doToQuery(QueryShardContext context) |
protected void |
doWriteTo(StreamOutput out) |
protected void |
doXContent(XContentBuilder builder,
ToXContent.Params params) |
protected void |
extractInnerHitBuilders(java.util.Map<java.lang.String,InnerHitContextBuilder> innerHits)
For internal usage only!
Extracts the inner hits from the query tree.
|
java.util.List<QueryBuilder> |
filter()
Gets the queries that must appear in the matching documents but don't contribute to scoring
|
BoolQueryBuilder |
filter(QueryBuilder queryBuilder)
Adds a query that must appear in the matching documents but will
not contribute to scoring.
|
static BoolQueryBuilder |
fromXContent(QueryParseContext parseContext) |
java.lang.String |
getWriteableName()
Returns the name of the writeable object
|
boolean |
hasClauses()
Returns
true iff this query builder has at least one should, must, must not or filter clause. |
java.lang.String |
minimumShouldMatch() |
BoolQueryBuilder |
minimumShouldMatch(int minimumShouldMatch)
Specifies a minimum number of the optional (should) boolean clauses which must be satisfied.
|
BoolQueryBuilder |
minimumShouldMatch(java.lang.String minimumShouldMatch)
Sets the minimum should match parameter using the special syntax (for example, supporting percentage).
|
java.util.List<QueryBuilder> |
must()
Gets the queries that must appear in the matching documents.
|
BoolQueryBuilder |
must(QueryBuilder queryBuilder)
Adds a query that must appear in the matching documents and will
contribute to scoring.
|
java.util.List<QueryBuilder> |
mustNot()
Gets the queries that must not appear in the matching documents.
|
BoolQueryBuilder |
mustNot(QueryBuilder queryBuilder)
Adds a query that must not appear in the matching documents.
|
java.util.List<QueryBuilder> |
should()
Gets the list of clauses that should be matched by the returned documents.
|
BoolQueryBuilder |
should(QueryBuilder queryBuilder)
Adds a clause that should be matched by the returned documents.
|
addValidationError, boost, boost, convertToBytesRefIfString, convertToStringIfBytesRef, declareStandardFields, equals, 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 ADJUST_PURE_NEGATIVE_DEFAULT
public BoolQueryBuilder()
public BoolQueryBuilder(StreamInput in) throws java.io.IOException
java.io.IOException
protected void doWriteTo(StreamOutput out) throws java.io.IOException
doWriteTo
in class AbstractQueryBuilder<BoolQueryBuilder>
java.io.IOException
public BoolQueryBuilder must(QueryBuilder queryBuilder)
public java.util.List<QueryBuilder> must()
public BoolQueryBuilder filter(QueryBuilder queryBuilder)
public java.util.List<QueryBuilder> filter()
public BoolQueryBuilder mustNot(QueryBuilder queryBuilder)
public java.util.List<QueryBuilder> mustNot()
public BoolQueryBuilder should(QueryBuilder queryBuilder)
SHOULD
clauses must match a document
for the BooleanQuery to match. No null value allowed.minimumShouldMatch(int)
public java.util.List<QueryBuilder> should()
should(QueryBuilder)
,
minimumShouldMatch(int)
public java.lang.String minimumShouldMatch()
public BoolQueryBuilder minimumShouldMatch(java.lang.String minimumShouldMatch)
minimumShouldMatch(int)
public BoolQueryBuilder minimumShouldMatch(int minimumShouldMatch)
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.
minimumShouldMatch
- the number of optional clauses that must matchpublic boolean hasClauses()
true
iff this query builder has at least one should, must, must not or filter clause.
Otherwise false
.public BoolQueryBuilder adjustPureNegative(boolean adjustPureNegative)
MatchAllDocsQuery
in order to act
as a pure exclude. The default is true
.public boolean adjustPureNegative()
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
doXContent
in class AbstractQueryBuilder<BoolQueryBuilder>
java.io.IOException
public static BoolQueryBuilder fromXContent(QueryParseContext parseContext) throws java.io.IOException, ParsingException
java.io.IOException
ParsingException
public java.lang.String getWriteableName()
NamedWriteable
protected org.apache.lucene.search.Query doToQuery(QueryShardContext context) throws java.io.IOException
doToQuery
in class AbstractQueryBuilder<BoolQueryBuilder>
java.io.IOException
protected int doHashCode()
doHashCode
in class AbstractQueryBuilder<BoolQueryBuilder>
protected boolean doEquals(BoolQueryBuilder other)
AbstractQueryBuilder
QueryBuilder
object of the same type is "equal to" this one.doEquals
in class AbstractQueryBuilder<BoolQueryBuilder>
protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws java.io.IOException
doRewrite
in class AbstractQueryBuilder<BoolQueryBuilder>
java.io.IOException
protected void extractInnerHitBuilders(java.util.Map<java.lang.String,InnerHitContextBuilder> innerHits)
AbstractQueryBuilder
extractInnerHitBuilders
in class AbstractQueryBuilder<BoolQueryBuilder>