# Shard Request Cache and Scripts

**URL:** <https://discuss.elastic.co/t/shard-request-cache-and-scripts/151273>\
**Category:** Elasticsearch\
**Created:** [October 5, 2018, 7:01pm UTC](https://discuss.elastic.co/t/shard-request-cache-and-scripts/151273 "2018-10-05T19:01:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luissantos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luissantos/32/36197_2.png) [@luissantos](https://discuss.elastic.co/u/luissantos)\
**Post date:** [October 5, 2018, 7:01pm UTC](https://discuss.elastic.co/t/shard-request-cache-and-scripts/151273/1 "2018-10-05T19:01:27Z")

</div>

Hi everyone,

I'm new to Elasticsearch and I've been trying to understand why my query is not being cached.

I've read the documentation ([Shard request cache settings | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-request-cache.html) ) several times but I couldn't find any evidence that queries containing scripts cannot be cached.

Sample request:

> GET /my\_index/\_search?request\_cache=true  
> {  
> "size": 0,  
> "aggs": {  
> "groupByOperator": {  
> "terms": {  
> "field": "operator",  
> "size": 10,  
> "order": {  
> "total": "desc"  
> }  
> },  
> "aggs": {  
> "total": {  
> "sum": {  
> "script": {  
> "source": "return doc['field1'].value + doc['field2'].value;"  
> }  
> }  
> }  
> }  
> }  
> }  
> }

Any idea?

Thanks.

---

<div class="post-metadata">

**Author:** ![s1monw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/s1monw/32/3637_2.png) [@s1monw](https://discuss.elastic.co/u/s1monw)\
**Post date:** [October 12, 2018, 11:38am UTC](https://discuss.elastic.co/t/shard-request-cache-and-scripts/151273/2 "2018-10-12T11:38:48Z")

</div>

it's correct that we don't cache scripts today since we can't guarantee that a user doesn't have any API calls in their scrips that violates the requirements for caching. In particular this is that scripts are idempotent. There are possibilities today to theoretically call a date API that takes now() into account. We might be able to revisit this behavior. Would you mind opening an issue on our github tracker and mention me there, the handle is the same

---

<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:** [November 9, 2018, 11:39am UTC](https://discuss.elastic.co/t/shard-request-cache-and-scripts/151273/3 "2018-11-09T11:39:57Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
