Slow Terms Aggregation

Hi, I hava a problem with es query and aggregation. All es record count is about 0.1 billion, before adding a terms aggregation, my query is fast, only cost 75ms and all hit count is 105. But after adding a aggregation, like this one:
{
"query": {
...
},
"aggs": {
"index": {
"terms": {
"field": "index"
}
}
}
}
this query will cost 20 second!
My question is: my query result count is only 105, why the aggregation is so slow?
Thanks for any reply!

When we gather terms in results we can either gather the full-strings in memory or what we call a "global ordinal" which is much more compact. The ordinal is a number which is given to every unique string and it is this process of determining the strings->numbers lookup that can be expensive on an index that is still constantly being written to. So given the low number of search results maybe you'd be better served by using raw strings rather than the ordinals which is the map execution hint.

What is the number of unique terms for the field in question, out of interest?

When I use map execution hint, query is faster than before, thanks.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

As @Mark_Harwood mentioned, this sounds like it is due to computation of global ordinals. A detailed description of this issue and several approaches to improve such performance (including the execution_hint:map) are given in the following blog post.