身安不如心安,屋宽不如心宽 。

multi_terms非常慢 耗时是Composite聚合的10倍

Elasticsearch | 作者 at1559 | 发布于2021年09月23日 | 阅读数:1421

EventTime大于2014-03-19 00:00:00的数据量有600W,需要通过OS和Sex两个字段聚合,即select count(1) from test_index group by OS, Sex。 用Composite Aggs和Multi Terms Aggs性能差异巨大,profiler看到Multi Terms Aggs聚合的90%的耗时都在aggs阶段的collec。   有大神知道为什么Multi Term Aggs比Composite Aggs慢这么多吗?

Composite Aggs耗时:1187ms
Multi Terms Aggs耗时:16359ms  
总的bucket都是150个,也就是2种查询方式都是查出全部的bucket了,但速度相差10倍,有大神解解答下吗?
 
Composite Aggs查询语句
POST test_index/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{"range": {
"EventTime": {"gte":"2014-03-19 00:00:00"}
}}
]}},
"aggs": {
"test": {
"composite" : {
"size": 200,
"sources" : [
{ "OS": { "terms": {"field": "OS" } } },
{ "Sex": { "terms": {"field": "Sex" } } }
]
}
}
}
}
Multi Terms Aggs查询语句
POST test_index/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{"range": {
"EventTime": {"gte":"2014-03-19 00:00:00"}
}}
]}},
"aggs": {
"test": {
"multi_terms": {
"size":200
"terms": [{
"field": "OS"
}, {
"field": "Sex"
}]
}
}
}
}
已邀请:

caster_QL

赞同来自:

官网说明:
https://www.elastic.co/guide/e ... .html
 
The multi_term aggregations are the most useful when you need to sort by a number of document or a metric aggregation on a composite key and get top N results. If sorting is not required and all values are expected to be retrieved using nested terms aggregation or composite aggregations will be a faster and more memory efficient solution.

caster_QL

赞同来自:

官网有说明,二者适合的场景:https://www.elastic.co/guide/e ... -size

要回复问题请先登录注册