We have a certain set of boolean-filtered term queries with aggregations (using
"size": 0) that are slow to run (5-10 seconds over 300M documents in 60 shards) yet are crucial to our app. Some of these queries match all documents in the index if the user selects a wide enough range. I'm giving plenty of memory to the shard request cache and node query cache. In addition, we refresh our indexes infrequently and are willing to pay at index time for fast queries.
Currently Elasticsearch seems to decide on its own when to cache a certain result. I've had to rerun each query 4-5 times in a row before it is cached. Since my set of crucial queries could be up to a few thousand distinct queries with all filter/aggregation permutations, it's unlikely that they will all be used frequently enough to be cached, and it's not a reasonable workaround to rig up a system that occasionally reruns them to ensure they stay cached.
What I'd like to be able to do is have more control over how these queries are cached: cache them the first time they are issued, and ensure they will never be evicted unless the index is refreshed.
Without better control over the caching, the only solution I've seen online is an undocumented setting
index.queries.cache.everything: true, which I'd rather not rely on (and I don't know if it even still works).
Are there any other levers I can use to control caching?