赞
踩
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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。