Medium zalando search

What is the difference between query context and filter context, and why does it matter?

The 30 second answer

A clause in query context contributes to the relevance score. A clause in filter context only decides yes or no and is not scored. Exact constraints such as size, brand, in stock or price range belong in filters. They skip scoring, Elasticsearch can cache frequently used filters, and they keep the score about text relevance rather than about whether a filter matched.

From the Elasticsearch docs. In query context, a clause answers "how well does this document match?" and adds to _score. In filter context, it answers "does this document match?" with yes or no. The docs list the benefits: filters do not compute scores, so they run faster; Elasticsearch automatically caches frequently used filters; and they use less CPU than full-text queries. Filter context applies to the filter and must_not clauses of a bool query and to filter aggregations, among others.

{"query": {"bool": {
  "must":   [{"match": {"title": "linen dress"}}],
  "filter": [{"term": {"size": "M"}}, {"term": {"in_stock": true}},
             {"range": {"price": {"lte": 80}}}]
}}}

Why it matters for relevance. If "size M" sat in must, every matching document would get the same small score boost, distorting the ranking for no reason. In filters, only the text decides the score.

Why it matters for latency. Facet and filter combinations repeat a lot in e-commerce, so cacheable filters help. Zalando's December 2025 post describes caching popular queries and filter combinations at several layers above Elasticsearch as well.

Common mistake. Putting the user's typed text into a filter, which loses ranking, or putting structured attributes extracted from the query into scoring. Zalando's public talks describe recognising entities such as brand or colour in the query and turning them into filters; treat that as a query-understanding step before the query reaches Elasticsearch.

Sources (3)
  1. Elasticsearch docs: Query and filter context
  2. Zalando Engineering: The Day Our Own Queries DoS'ed Us: Inside Zalando Search (December 2025)
  3. MICES 2026: Zalando Search: Architecture Behind Product Discovery (video)