# Shard query cache - TTL invalidation?

**URL:** https://discuss.elastic.co/t/shard-query-cache-ttl-invalidation/20909
**Category:** Elasticsearch
**Created:** [November 24, 2014, 10:51am UTC](https://discuss.elastic.co/t/shard-query-cache-ttl-invalidation/20909 "2014-11-24T10:51:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lasseschou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lasseschou/32/845_2.png) [@lasseschou](https://discuss.elastic.co/u/lasseschou)
#### Post date: [November 24, 2014, 10:51am UTC](https://discuss.elastic.co/t/shard-query-cache-ttl-invalidation/20909/1 "2014-11-24T10:51:31Z")

</div>

Hi,

The way I understand the Shard Query Cache  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/index-modules-shard-query-cache.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/index-modules-shard-query-cache.html),  
it invalidates \*ALL \*cached results in a shard when the shard refreshes,  
given that \*ANY \*data in the shard has changed.

My data changes all the time, but I'd like to keep some of my query results  
cached for a while - say 1 minute.

My refresh interval (5 sec) cannot be changed because I need near-realtime  
searches for other query types.

I can read that there is a "indices.cache.query.expire" config setting  
where the general TTL of all Shard Query Caches can be set, but the docs  
specify that this shouldn't really be used because all cached results are  
invalidated anyway upon refresh.

Two questions:

1. Is my understanding of the Shard Query Cache invalidation mechanism  
correct?
2. Is there a way to specify a TTL on the query-level, that makes the  
cached result survive the refresh interval?

Thanks,  
Lasse

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c6dd35c7-e1f8-4bd1-9136-6cfaacfabf1e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c6dd35c7-e1f8-4bd1-9136-6cfaacfabf1e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [November 25, 2014, 9:22pm UTC](https://discuss.elastic.co/t/shard-query-cache-ttl-invalidation/20909/2 "2014-11-25T21:22:02Z")

</div>

Hi,

On Mon, Nov 24, 2014 at 11:51 AM, Lasse Schou [lasseschou@gmail.com](mailto:lasseschou@gmail.com) wrote:

> The way I understand the Shard Query Cache  
> [http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/index-modules-shard-query-cache.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/index-modules-shard-query-cache.html),  
> it invalidates \*ALL \*cached results in a shard when the shard refreshes,  
> given that \*ANY \*data in the shard has changed.

This is correct.

> My data changes all the time, but I'd like to keep some of my query  
> results cached for a while - say 1 minute.
> 
> My refresh interval (5 sec) cannot be changed because I need near-realtime  
> searches for other query types.
> 
> I can read that there is a "indices.cache.query.expire" config setting  
> where the general TTL of all Shard Query Caches can be set, but the docs  
> specify that this shouldn't really be used because all cached results are  
> invalidated anyway upon refresh.

The thing is that we wanted this cache to give accurate results: no matter  
if it is enabled or not you are going to get the same results. (just like  
the filter caches and fielddata caches).

In your case, I think the best option would be to put a cache in front of  
elasticsearch?

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4u3LMmm3EcLiPH3aacx4QJM70Vfbn2kzKWhVZOxDY52Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4u3LMmm3EcLiPH3aacx4QJM70Vfbn2kzKWhVZOxDY52Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![lasseschou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lasseschou/32/845_2.png) [@lasseschou](https://discuss.elastic.co/u/lasseschou)
#### Post date: [November 25, 2014, 9:33pm UTC](https://discuss.elastic.co/t/shard-query-cache-ttl-invalidation/20909/3 "2014-11-25T21:33:25Z")

</div>

Got it, thanks.

Lasse

Den tirsdag den 25. november 2014 skrev Adrien Grand \<  
[adrien.grand@elasticsearch.com](mailto:adrien.grand@elasticsearch.com)\>:

> Hi,
> 
> On Mon, Nov 24, 2014 at 11:51 AM, Lasse Schou \<[lasseschou@gmail.com](mailto:lasseschou@gmail.com)  
> \<javascript:\_e(%7B%7D,'cvml','lasseschou@gmail.com');\>\> wrote:
> 
> > The way I understand the Shard Query Cache  
> > [http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/index-modules-shard-query-cache.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.4/index-modules-shard-query-cache.html),  
> > it invalidates \*ALL \*cached results in a shard when the shard refreshes,  
> > given that \*ANY \*data in the shard has changed.
> 
> This is correct.
> 
> > My data changes all the time, but I'd like to keep some of my query  
> > results cached for a while - say 1 minute.
> > 
> > My refresh interval (5 sec) cannot be changed because I need  
> > near-realtime searches for other query types.
> > 
> > I can read that there is a "indices.cache.query.expire" config setting  
> > where the general TTL of all Shard Query Caches can be set, but the docs  
> > specify that this shouldn't really be used because all cached results are  
> > invalidated anyway upon refresh.
> 
> The thing is that we wanted this cache to give accurate results: no matter  
> if it is enabled or not you are going to get the same results. (just like  
> the filter caches and fielddata caches).
> 
> In your case, I think the best option would be to put a cache in front of  
> elasticsearch?
> 
> --  
> Adrien Grand
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/mJGQ6TWwIXc/unsubscribe](https://groups.google.com/d/topic/elasticsearch/mJGQ6TWwIXc/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com)  
> \<javascript:\_e(%7B%7D,'cvml','elasticsearch%2Bunsubscribe@googlegroups.com');\>  
> .  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4u3LMmm3EcLiPH3aacx4QJM70Vfbn2kzKWhVZOxDY52Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4u3LMmm3EcLiPH3aacx4QJM70Vfbn2kzKWhVZOxDY52Q%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4u3LMmm3EcLiPH3aacx4QJM70Vfbn2kzKWhVZOxDY52Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4u3LMmm3EcLiPH3aacx4QJM70Vfbn2kzKWhVZOxDY52Q%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CADERWXpyGCfxxB6pbR%3D4Q-J-EKMXAN3DgYaOs8p5FX9W2LfSnw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CADERWXpyGCfxxB6pbR%3D4Q-J-EKMXAN3DgYaOs8p5FX9W2LfSnw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:47am UTC](https://discuss.elastic.co/t/shard-query-cache-ttl-invalidation/20909/4 "2017-07-06T00:47:37Z")

</div>


