Elasticsearch 去重统计 cardinality去重复
程序员文章站
2024-03-23 21:06:22
...
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
上一篇: Mac启用Root用户
下一篇: SQL——分组比较