Reference · Cheat sheet
The compressed essence. Print it, pin it.
| Query context | Filter context | |
|---|---|---|
| Question asked | How well does it match? | Does it match — yes/no? |
| Produces _score? | Yes (BM25) | No (score irrelevant) |
| Cacheable? | No | Yes — node query cache (bitsets) |
| bool keys | must, should | filter, must_not |
| Use for | Full-text, relevance ranking | Exact constraints: status, dates, tags, ranges |
GET /articles/_search
{
"query": {
"bool": {
"must": { "match": { "title": "elasticsearch tuning" } }, // scored
"filter": [
{ "term": { "status": "published" } }, // yes/no, cached
{ "range": { "published_at": { "gte": "2024-01-01" } } }
]
}
}
}
filter.must adds to _score.constant_score.Putting exact constraints (e.g. term status=active) inside must. It still works, but you pay for scoring you throw away and lose the filter cache. Move it to filter.
← lesson 0001 · Source: Elastic Docs — Query and filter context