I have an Elasticsearch query that returns only 107 documents but takes 1.5 seconds to execute. When I remove one specific aggregation (values_brand), the same query completes in 100ms. The brand field only contains 8 unique values (although it is a high cardinality field in general, ~200k unique values) in the result set, so I'm confused why this aggregation is causing such a significant performance impact.
Query:
{
"track_total_hits": true,
"size": 100,
"query": {
"query_string": {
"query": "<some query>",
"default_field": "<some default field>"
}
},
"aggs": {
"values_retailer": {
"terms": {
"size": 5,
"field": "retailer"
}
},
"values_brand": {
"terms": {
"size": 5,
"field": "brand"
}
},
"values_subindustry": {
"terms": {
"size": 5,
"field": "subindustry"
}
}
}
}
retailer
, brand
and subindustry
are all mapped to keyword
field type. Elasticsearch version is 9.0.3.
I have also noticed that if I add "execution_hint": "map"
to values_brand
aggregation, the speed is greatly improved. However, only for the cases with a handful search results.