Boolean query #
A query that matches documents matching boolean combinations of other queries. It is built using one or more boolean clauses.
Inside a
nestedquery: supported —must/filter/should/must_notandminimum_should_matchall apply within ONE array element; clauses matched by different elements never combine.
Examples #
POST /my-collection/_search
{
"query": {
"bool": {
"must": [
{ "match": { "field": "title", "query": "search" } }
],
"filter": [
{ "term": { "field": "status", "value": "published" } }
],
"must_not": [
{ "range": { "field": "views", "gte": 100000 } }
],
"should": [
{ "term": { "field": "tags", "value": "featured" } }
],
"minimum_should_match": 1
}
}
}
Clause types #
must
The document must match. Contributes to the score.filter
The document must match. Does not contribute to the score — results may be cached by filter context.should
The document should match. Contributes to the score; required to match only when nomust/filterclauses are present (then at least oneshouldmust match) or whenminimum_should_matchis set.must_not
The document must not match. Does not contribute to the score.
Parameters for bool
#
minimum_should_match
(Optional, integer) Minimum number ofshouldclauses a document must match. The built-in default is1when the query hasshouldclauses but nomust/filter, otherwise0.score_mode
(Optional, string) Multi-field score combination strategy forshouldclauses:most_fields(sum — the default, for backward compatibility) orbest_fields(max, dis_max style).tie_breaker
(Optional, float, default:0) Tie-breaker forbest_fieldsmode. Final score:max_score + tie_breaker * sum(other_scores). Range[0, 1].combination_strategy
(Optional, string) Score combination strategy forshouldclauses across fields (best_fieldsormost_fields).