Elasticsearch 去重统计 按照deviceId 去重统计总数
相当于SQL
SELECT COUNT(DISTINCT deviceId ?) FROM log_info where userName= 'admin' and operateTime > '2020-05-18 00:00:00' and?perateTime < '2020-05-25 00:00:00'?
{
"query": {
"bool": {
"must": [{
"match": {
"userName": "admin"
}
}, {
"range": {
"operateTime": {
"gt": "2020-05-18 00:00:00",
"lt": "2020-05-25 00:00:00"
}
}
}],
"must_not": [],
"should": []
}
},
"from": 0,
"size": 0,
"sort": [],
"aggs": {
"deviceId_aggs": {
"cardinality": {
"field": "deviceId"
}
}
}
}

es在使用cardinality实现count(distinct)时会在准确性和及时性上做一定的取舍
可以在使用cardinality时,配置下面的参数来增加准确性,牺牲的是时间和内存
percision_threshold : 40000

本文介绍了如何使用Elasticsearch的聚合功能,通过cardinality实现SQL中的COUNT(DISTINCT)操作,针对特定条件进行deviceId的去重统计。同时,讨论了在保证准确性的前提下,如何通过调整percision_threshold参数来平衡性能和精度。
7182

被折叠的 条评论
为什么被折叠?



