聚合不准确,在官网文档中有解读:Document counts are approximateedit
As described above, the document counts (and the results of any sub aggregations) in the terms aggregation are not always accurate. This is because each shard provides its own view of what the ordered list of terms should be and these are combined to give a final view. Consider the following scenario:
2 个回复
chroje
赞同来自:
{
"query": {
"term": {
"jldbh": "0634090002765101"
}
},
"size": 100,
"_source": ["jldbh"]
}
返回
"hits": {
"total": 20,
}
发送
GET orcl-npmis_zw_ysdfmx_bak/_search
{
"size": 0,
"aggs": {
"a1": {
"terms": {
"size": 100,
"field": "jldbh.keyword",
"order": {
"a2": "desc"
}
},
"aggs": {
"a2": {
"sum": {
"field": "zdl"
}
}
}
}
}
}
返回
{
"key": "0634090002765101",
"doc_count": 19,
"a2": {
"value": 23727052.75
}
},
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自:
As described above, the document counts (and the results of any sub aggregations) in the terms aggregation are not always accurate. This is because each shard provides its own view of what the ordered list of terms should be and these are combined to give a final view. Consider the following scenario:
主要原因:是分片聚合返回数据。
参考:https://www.elastic.co/guide/e ... .html
解决方案:聚合的时候,size值设置的再大一些。