BoolQuery document (Data API 18.3)

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' OR 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 {BoolQuery, FilteredQuery, MatchAllQuery, NestedQuery, TermQuery, TextQuery}]   List of queries, which must match.
must_not [Query {BoolQuery, FilteredQuery, MatchAllQuery, NestedQuery, TermQuery, TextQuery}]   List of queries, which must not match.
should [Query {BoolQuery, FilteredQuery, MatchAllQuery, NestedQuery, TermQuery, TextQuery}]   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.
X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.