Class BoolQueryBuilder

    • Constructor Detail

      • BoolQueryBuilder

        public BoolQueryBuilder()
        Build an empty bool query.
      • BoolQueryBuilder

        public BoolQueryBuilder​(StreamInput in)
                         throws java.io.IOException
        Read from a stream.
        Throws:
        java.io.IOException
    • Method Detail

      • must

        public BoolQueryBuilder must​(QueryBuilder queryBuilder)
        Adds a query that must appear in the matching documents and will contribute to scoring. No null value allowed.
      • must

        public java.util.List<QueryBuilder> must()
        Gets the queries that must appear in the matching documents.
      • filter

        public BoolQueryBuilder filter​(QueryBuilder queryBuilder)
        Adds a query that must appear in the matching documents but will not contribute to scoring. No null value allowed.
      • filter

        public java.util.List<QueryBuilder> filter()
        Gets the queries that must appear in the matching documents but don't contribute to scoring
      • mustNot

        public BoolQueryBuilder mustNot​(QueryBuilder queryBuilder)
        Adds a query that must not appear in the matching documents. No null value allowed.
      • mustNot

        public java.util.List<QueryBuilder> mustNot()
        Gets the queries that must not appear in the matching documents.
      • should

        public BoolQueryBuilder should​(QueryBuilder queryBuilder)
        Adds a clause that should be matched by the returned documents. For a boolean query with no MUST clauses one or more SHOULD clauses must match a document for the BooleanQuery to match. No null value allowed.
        See Also:
        minimumShouldMatch(int)
      • minimumShouldMatch

        public java.lang.String minimumShouldMatch()
        Returns:
        the string representation of the minimumShouldMatch settings for this query
      • minimumShouldMatch

        public BoolQueryBuilder minimumShouldMatch​(java.lang.String minimumShouldMatch)
        Sets the minimum should match parameter using the special syntax (for example, supporting percentage).
        See Also:
        minimumShouldMatch(int)
      • minimumShouldMatch

        public BoolQueryBuilder minimumShouldMatch​(int 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()
        Returns true iff this query builder has at least one should, must, must not or filter clause. Otherwise false.
      • adjustPureNegative

        public 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. The default is true.
      • adjustPureNegative

        public boolean adjustPureNegative()
        Returns:
        the setting for the adjust_pure_negative setting in this query
      • getWriteableName

        public java.lang.String getWriteableName()
        Description copied from interface: NamedWriteable
        Returns the name of the writeable object