【发布时间】:2020-12-19 09:34:13
【问题描述】:
enter image description here
按字段聚合时userguid
{
"_source": false,
"aggregations": {
"range_userGuid": {
"terms": {
"field": "userGuid"
}
}
}
}
我得到结果
"aggregations" : {
"range_userGuid" : {
"doc_count_error_upper_bound" : 151,
"sum_other_doc_count" : 2424145,
"buckets" : [
{
"key" : 803100110976,
"doc_count" : 1
},
{
"key" : 813110447915,
"doc_count" : 10
},
{
"key" : 803100110306,
"doc_count" : 101
},
{
"key" : 2123312,
"doc_count" : 300
},
{
"key" : 3452342,
"doc_count" : 9999
},
]
}
}
现在我想从 aggs 结果中获取范围。例如(0-100],(100-1000],>1000,获取用户数。预期结果:
[
{
"from": 0,
"to": 100,
"count": 2 <---- 2 users, 803100110976 and 813110447915
},
{
"from": 100,
"to": "1000",
"count": 2 <---- 803100110306 and 2123312
},
{
"from": 1001,
"count": 1 <---- 3452342
}
]
aggs的bucket大小在150000左右,这样的查询怎么写?
【问题讨论】:
-
这能回答你的问题吗? Range ElasticSearch Aggregation
-
@Jian
userGuid字段的数据类型是什么?是数字吗? -
@Val
userGuid是数字,桶大小会大到150000左右
标签: elasticsearch elasticsearch-aggregation