Hello!
I have an elasticsearch cluster with daily indexes for some history functions. For another function, I only need the data for the last hour.
My query for this looks something like this:
{
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "now-1h"
}
}
},
{
"range": {
"field1": {
"lte": %{some_number}
}
}
},
{
"range": {
"field2": {
"gte": %{some_other_number}
}
}
},
{
"match": {
"textfield": "%{some_text}"
}
}
]
}
}
}
Only the documents which match all 4 of those clauses should be returned, which works great. Now, I have seen, that all Indices get queried, not only the newest one. This causes quite some load. According to this, the order of the clauses is determined by elasticsearch itself.
Can I influence this execution order somehow? i.e. I would like to execute the @timestamp-range clause first. Maybe a nested bool query...? And how does this work then? I don't see the sense in querying all of the indices because the needed documents clearly are in the newest one (or two) indices.