I finally got around to profile some slow running parts of our application and I found a query that is taking way too long and which also creates a good chunk of our cluster load. Profiling the query in Kibana revealed that most shards finish well below 10ms, but there are almost always a few random shards that take 10 seconds + (most of the time spent in the GlobalOrdinalsQuery.build_scorer).
I suspect that the has_parent query is run before the way more restrictive filters effectively joining billion of documents. Is there a way to enforce the filter order, e.g. rewrite the query to make sure the term filters are executed before the parent-child join madness?
The index refreshes every 120 seconds.
The query:
GET /user-v5/like/_search
{
"query": {
"bool": {
"filter": [
{
"terms": {
"post_id": [
1489831183823275924,
1489206393580157727
]
}
},
{
"term": {
"user_id": 587771206
}
},
{
"has_parent": {
"query": {
"bool": {
"filter": [
{
"term": {
"calculated": true
}
}
]
}
},
"score_mode": "none",
"parent_type": "user"
}
}
]
}
},
"from": 0,
"aggs": {
"per_post": {
"terms": {
"field": "post_id",
"size": 5
}
}
},
"size": 0
}