BoolQuery document (Data API 19.5)

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 Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. By continuing to use this site you are giving us your consent to do this.