Bool Queries
5 min read Quiz at the end
Combine must (required), should (boost), must_not, and filter clauses in bool queries.
Bool (Compound) Queries
# Bool query combines conditions
GET /posts/_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "docker" } },
{ "term": { "is_published": true } }
],
"should": [
{ "match": { "body": "container" } }
],
"must_not": [
{ "term": { "status": "draft" } }
],
"filter": [
{ "range": { "created_at": { "gte": "2024-01-01" } } }
]
}
}
}
# must — must match (affects score)
# should — nice to match (boosts score)
# must_not — must not match
# filter — must match (no scoring, cached)
Topic Quiz · 1 questions
Test your understanding before moving on
1. In a bool query, which clause caches results and does NOT affect relevance score?
💡 filter context is binary (match/no match), cached, and does not compute a relevance score.