org.elasticsearch.index.query
Class BoolQueryBuilder

java.lang.Object
  extended by org.elasticsearch.index.query.BaseQueryBuilder
      extended by org.elasticsearch.index.query.BoolQueryBuilder
All Implemented Interfaces:
ToXContent, BoostableQueryBuilder<BoolQueryBuilder>, QueryBuilder

public class BoolQueryBuilder
extends BaseQueryBuilder
implements BoostableQueryBuilder<BoolQueryBuilder>

A Query that matches documents matching boolean combinations of other queries.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.MapParams, ToXContent.Params
 
Field Summary
 
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
 
Constructor Summary
BoolQueryBuilder()
           
 
Method Summary
 BoolQueryBuilder boost(float boost)
          Sets the boost for this query.
 BoolQueryBuilder disableCoord(boolean disableCoord)
          Disables Similarity#coord(int,int) in scoring.
protected  void doXContent(XContentBuilder builder, ToXContent.Params params)
           
 boolean hasClauses()
          Return true if the query being built has no clause yet
 BoolQueryBuilder minimumNumberShouldMatch(int minimumNumberShouldMatch)
          Specifies a minimum number of the optional (should) boolean clauses which must be satisfied.
 BoolQueryBuilder minimumShouldMatch(String minimumShouldMatch)
          Sets the minimum should match using the special syntax (for example, supporting percentage).
 BoolQueryBuilder must(QueryBuilder queryBuilder)
          Adds a query that must appear in the matching documents.
 BoolQueryBuilder mustNot(QueryBuilder queryBuilder)
          Adds a query that must not appear in the matching documents.
 BoolQueryBuilder should(QueryBuilder queryBuilder)
          Adds a query that should appear in the matching documents.
 
Methods inherited from class org.elasticsearch.index.query.BaseQueryBuilder
buildAsBytes, buildAsBytes, toString, toXContent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BoolQueryBuilder

public BoolQueryBuilder()
Method Detail

must

public BoolQueryBuilder must(QueryBuilder queryBuilder)
Adds a query that must appear in the matching documents.


mustNot

public BoolQueryBuilder mustNot(QueryBuilder queryBuilder)
Adds a query that must not appear in the matching documents.


should

public BoolQueryBuilder should(QueryBuilder queryBuilder)
Adds a query that should appear in the matching documents. For a boolean query with no MUST clauses one or more SHOULD clauses must match a document for the BooleanQuery to match.

See Also:
minimumNumberShouldMatch(int)

boost

public BoolQueryBuilder boost(float 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 interface BoostableQueryBuilder<BoolQueryBuilder>

disableCoord

public BoolQueryBuilder disableCoord(boolean disableCoord)
Disables Similarity#coord(int,int) in scoring. Defualts to false.


minimumNumberShouldMatch

public BoolQueryBuilder minimumNumberShouldMatch(int minimumNumberShouldMatch)
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:
minimumNumberShouldMatch - the number of optional clauses that must match

minimumShouldMatch

public BoolQueryBuilder minimumShouldMatch(String minimumShouldMatch)
Sets the minimum should match using the special syntax (for example, supporting percentage).


hasClauses

public boolean hasClauses()
Return true if the query being built has no clause yet


doXContent

protected void doXContent(XContentBuilder builder,
                          ToXContent.Params params)
                   throws IOException
Specified by:
doXContent in class BaseQueryBuilder
Throws:
IOException


Copyright © 2009-2012. All Rights Reserved.