Shard Request Cache and Scripts


(Luis Santos) #1

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 (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.


(Simon Willnauer) #2

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