# Per type Query Cache invalidation

**URL:** https://discuss.elastic.co/t/per-type-query-cache-invalidation/42154
**Category:** Elasticsearch
**Created:** [February 18, 2016, 4:08pm UTC](https://discuss.elastic.co/t/per-type-query-cache-invalidation/42154 "2016-02-18T16:08:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![xam](https://avatars.discourse-cdn.com/v4/letter/x/bb73d2/32.png) [@xam](https://discuss.elastic.co/u/xam)
#### Post date: [February 18, 2016, 4:08pm UTC](https://discuss.elastic.co/t/per-type-query-cache-invalidation/42154/1 "2016-02-18T16:08:28Z")

</div>

Hi all,

I am confused about cache invalidation. It seams that filter cache is per segment. That means that I can add data without totally invalidating this cache. Is it the same for ShardQueryCache? Can I add data without invalidating that cache?

Thank you.

---

<div class="post-metadata">

### Author: ![xam](https://avatars.discourse-cdn.com/v4/letter/x/bb73d2/32.png) [@xam](https://discuss.elastic.co/u/xam)
#### Post date: [February 22, 2016, 2:29pm UTC](https://discuss.elastic.co/t/per-type-query-cache-invalidation/42154/2 "2016-02-22T14:29:55Z")

</div>

Hi,

I finally found the answer in the following thread:  
[http://elasticsearch-users.115913.n3.nabble.com/Shard-query-cache-size-td4074827.html](http://elasticsearch-users.115913.n3.nabble.com/Shard-query-cache-size-td4074827.html)  
where Adrien Grand mentions that :  
"- the query cache caches entire requests per index, and is competely invalidated across all data every time the refresh interval ticks over AND there have been changes since the last refresh

- the filter cache caches matching documents per segment, it is invalidated per segment only when a segment goes away (typically because it's been merged to a larger segment), which is unfrequent for large segments
- the fielddata cache caches the document-\>value mapping per segment and has the same invalidation rules as the filter cache"  
So the shard query cache is not per segment. It is a pity because if we have an index with two types : Updating data of one type will invalidate the cache for the other type.  
Do you know if this is an issue that can be addressed or if there is underlying restriction due to the shard structure that prevent from doing per type query cache.

Thank you,

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [February 22, 2016, 6:28pm UTC](https://discuss.elastic.co/t/per-type-query-cache-invalidation/42154/3 "2016-02-22T18:28:46Z")

</div>

Sorry I think there is some confusion due to the fact that we merged queries and filters and renamed the filter cache to query cache, and the query cache to request cache.

In short the query cache caches data for individual queries per segment. This makes it likely to be reused even if you keep adding data since large segments typically get merged very rarely.

On the other hand, the request cache caches entire search requests and is discarded every time you do a refresh, so every one second by default if you keep indexing data. This cache is typically useful if eg. you have an analytics dashboard that many clients keep refreshing, which ends up making the same request to elasticsearch all the time.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:14pm UTC](https://discuss.elastic.co/t/per-type-query-cache-invalidation/42154/4 "2017-07-05T23:14:24Z")

</div>


