BoolQuery document (Data API 23.2)

A boolean query allows construction of 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 that must match.
must_not [Query {BoolQuery, FilteredQuery, MatchAllQuery, NestedQuery, TermQuery, TextQuery}]   List of queries that must not match.
should [Query {BoolQuery, FilteredQuery, MatchAllQuery, NestedQuery, TermQuery, TextQuery}]   List of queries that 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.
Notifications pending to read 9