The 30 second answer
The node query cache stores which documents match a filter-context clause, per segment, up to 10% of heap by default; term queries and scoring clauses aren't eligible. The shard request cache stores whole responses, by default only for size zero requests like facet counts, keyed by a hash of the entire JSON body and cleared on every refresh. So keep filters in filter context, round dates, build request JSON deterministically, and don't refresh more often than needed.
Two different caches inside Elasticsearch.
| Node query cache | Shard request cache | |
|---|---|---|
| Caches | Which documents match a filter clause | The whole shard-level response |
| Scope | Per segment, shared by all shards on the node | Per shard |
| Eligible | Clauses in filter context (term queries excluded) | By default requests with size=0 (aggregations, counts) |
| Invalidated | When segments change (merges) | On every refresh, and on mapping changes |
| Default size | 10% of heap, up to 10,000 queries | Bounded by a setting, LRU eviction |
The docs on the query cache: "The results of queries used in the filter context are cached", "Term queries and queries used outside of a filter context are not eligible for caching", and caching only happens for clauses that recur and for segments that are large enough. On the request cache: "By default, the request cache will only cache the results of search requests where size=0", the cache key is "a hash of the whole JSON body", so "if keys are output in a different order" the key changes, and "requests using now cannot be cached". Results "are invalidated automatically whenever the shard refreshes".
Badly written. Filters in must (not cached), keys in random order per request, now without rounding, and a 1-second refresh on an index that changes constantly:
{ "size": 0,
"query": { "bool": { "must": [
{ "range": { "created_at": { "gte": "now-7d" } } },
{ "terms": { "category_id": ["dresses", "skirts"] } } ] } },
"aggs": { "brands": { "terms": { "field": "brand_id" } } } }Better. Filter context, rounded dates, a stable JSON builder in the search API layer:
{ "size": 0,
"query": { "bool": { "filter": [
{ "terms": { "category_id": ["dresses", "skirts"] } },
{ "range": { "created_at": { "gte": "now-7d/d" } } } ] } },
"aggs": { "brands": { "terms": { "field": "brand_id", "size": 30 } } } }What about application caches? Zalando's outage write-up describes caching popular queries and filter combinations in the query builder and catalog layers, plus dedicated coordinator nodes. It also notes that a longer cache TTL did not save them during the incident. Caches help with normal repeated traffic; unusual or highly varied queries miss every layer.
Trade-offs.
- A longer
refresh_intervalkeeps request-cache entries valid longer and makes indexing cheaper, at the cost of freshness. eBay's Elasticsearch tuning post makes the same point about refresh and caching. - Caching full pages with
size > 0is possible per request (request_cache=true), but per-shopper sorts and personalization make hit rates low.
Alternate interview scenarios
"Facet requests are identical but the request cache hit rate is near zero."
Check refresh frequency (every refresh clears it), whether the JSON is byte-identical (key order, float formatting), and whether now or a per-user parameter sneaks into the body.
"Should price and stock be cached at all?"
Shard caches stay correct because they're cleared on refresh. Application caches in front of search need short TTLs or event-driven invalidation for volatile fields, which the product-search system design page covers.
Sources (4)
- Elasticsearch docs: Node query cache settingselastic.co
- Elasticsearch docs: Shard request cacheelastic.co
- Zalando Engineering: The Day Our Own Queries DoS'ed Us: Inside Zalando Search (December 2025)engineering.zalando.com
- eBay Tech Blog: Elasticsearch Performance Tuning Practice at eBayinnovation.ebayinc.com