Generally it is mentioned that filter queries are open to be cached and the must ones not.
but here I have some important questions from easy to complex ones. if any of my statements and deductions were false, it would be nice to mention
1- imagine using such a simple below query:
{
"bool": {
"filter": [ { term }, ... ],
"must": [ { term }, { match }, ... ]
}
}
the filter section is possible to be cached (based on elastic documents) and the must section, regardless of the query type it is used (term, match, multimatch, etc) would not be cached.
(NOTICE: if anything is wrong please mention)
2- now lets take a look at below one, which only contains must queries which cannot be cached:
{
"bool": {
"must": [ { term }, { match }, ... ]
}
}
lets call above query as Q-1
what if I wrap the above query inside a filter one to escape all scorings and improve search speed? as below:
{
"bool": {
"filter": [
Q-1
]
}
}
now what happends?
does elastic caches the general answer of the Q-1 query as a single query result or it will use separate caches for each query (ex: term query) used inside the must section?
I generally mean that does this wrapping, just prevent the scoring phase to be executed or also affect the caching as well, so that cause another enhancements on search performance?
3- currently I am using above technique in my production actually, and I was wondering is there anyway to check which parts are being cached or not. how to do so? how can I check which parts of a query are possible to be cached by elastic?
NOTE: it would be nice to also refer to the code where all these decisions are made inside elastic github.