Reference · Cheat sheet

Query vs Filter context

The compressed essence. Print it, pin it.

From lesson 0001See also glossary

 Query contextFilter context
Question askedHow well does it match?Does it match — yes/no?
Produces _score?Yes (BM25)No (score irrelevant)
Cacheable?NoYes — node query cache (bitsets)
bool keysmust, shouldfilter, must_not
Use forFull-text, relevance rankingExact constraints: status, dates, tags, ranges

Canonical shape

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" } } }
      ]
    }
  }
}

Rules of thumb

Common mistake

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