我写了一些aggs查询来获得总计(总和)和唯一计数。 但结果有点困惑。
唯一值大于doc_count 可能吗?
我知道基数aggs是实验性的,可以得到不同值的近似计数 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
但结果太差了。
正如你所看到的那样,有许多独特的桶比doc_count大。
请求格式有什么问题吗?或基数限制?
请求
{
"size": 0,
"_source": false,
"aggs": {
"eventIds": {
"terms": {
"field": "_EventID_",
"size": 0
},
"aggs": {
"unique": {
"cardinality": {
"field": "UUID"
}
}
}
}
}
回复
{
"took": 383,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 550971,
"max_score": 0,
"hits": [
]
},
"aggregations": {
"eventIds": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "red",
"doc_count": 165110,
"unique": {
"value": 27423
}
},
{
"key": "blue",
"doc_count": 108376,
"unique": {
"value": 94775
}
},
{
"key": "yellow",
"doc_count": 78919,
"unique": {
"value": 70094
}
},
{
"key": "green",
"doc_count": 60580,
"unique": {
"value": 78945
}
},
{
"key": "black",
"doc_count": 49923,
"unique": {
"value": 56200
}
},
{
"key": "white",
"doc_count": 38744,
"unique": {
"value": 45229
}
},
我再次尝试使用1,000精度阈值,仅过滤了一个eventId
但结果的错误是一样的。
基数预计低于30,000,但超过66,000(这大于文件总大小)
doc_count:65,672(没问题。右) 基数:66,037(大于doc_count) 实际基数:约23,000(由rdbms脚本计算......)
请求
{
"size": 0,
"_source": false,
"query": {
"term": {
"_EventID_": "packdownload"
}
},
"aggs": {
"unique": {
"cardinality": {
"field": "UUID",
"precision_threshold": 10000
}
}
}
}
回复
{
"took": 28,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 65672,
"max_score": 0,
"hits": []
},
"aggregations": {
"unique": {
"value": 66037
}
}
}
答案 0 :(得分:1)
精度阈值的最高值为40,000。这应该会略微改善结果,但是如果计算出明显不同的值,则可能会出现20%加上减去的误差。它甚至会以较低的值发生。