BoolQuery Document (Data API 17.4)

A boolean query allows to construct full logical expression trees consisting of other queries (usually term and text queries). A boolean query basically has 3 sets of clauses that 'must', 'should' and / or 'must not' match. If 'must', 'must_not', or 'should' appear in the same boolean query, they are combined logically using the AND operator. Example: (id = 'foo' AND description LIKE 'bar')
    query: {
        bool_query: {
            must: [
                { term_query: { fields: ["id"], operator: "is", values: ["foo"] } },
                { text_query: { fields: ["description"], search_phrase: "bar" } }
            ]
        }
    }
 
Example: (id = 'foo' OR description LIKE 'bar')
    query: {
        bool_query: {
            should: [
                { term_query: { fields: ["id"], operator: "is", values: ["foo"] } },
                { text_query: { fields: ["description"], search_phrase: "bar" } }
            ]
        }
    }
 
Example: (NOT (id = 'foo' AND description LIKE 'bar'))
    query: {
        bool_query: {
            must_not: [
                { term_query: { fields: ["id"], operator: "is", values: ["foo"] } },
                { text_query: { fields: ["description"], search_phrase: "bar" } }
            ]
        }
    }
 
Example: ((coupon_id LIKE "limit" AND description LIKE "limit per customer") AND NOT (enabled=false))
    query: {
        bool_query: {
            must: [
                { text_query: { fields: [ "coupon_id" ], search_phrase: "limit" } },
                { text_query: { fields: [ "description" ], search_phrase: "limit per customer" } }
            ],
            must_not: [
                { term_query: { fields: [ "enabled" ], operator: "is", values: [false] } }
            ]
        }
    }
 
Property Type Constraints Description
must [Query {TermQuery, TextQuery, BoolQuery, MatchAllQuery, FilteredQuery}]   List of queries, which must match.
must_not [Query {TermQuery, TextQuery, BoolQuery, MatchAllQuery, FilteredQuery}]   List of queries, which must not match.
should [Query {TermQuery, TextQuery, BoolQuery, MatchAllQuery, FilteredQuery}]   List of queries, which should match.
X OCAPI versions 15.x and 16.x will be retired on March 31, 2021. For dates and more information, see the OCAPI versioning and deprecation policy and this Knowledge Article.