要不要再翻翻文档呢?

聚合分组结果集的数目不准确

Elasticsearch | 作者 chroje | 发布于2018年04月30日 | 阅读数:2253

通过term匹配有20条记录,也确实含有20条记录,但是通过terms -- field.keyword分组匹配之后记录只返回了19条。
已邀请:

chroje

赞同来自:

发送POST /orcl-npmis_zw_ysdfmx_bak/_search
{
  "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

赞同来自:

聚合不准确,在官网文档中有解读: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:
 
主要原因:是分片聚合返回数据。
参考:https://www.elastic.co/guide/e ... .html
 
解决方案:聚合的时候,size值设置的再大一些。

要回复问题请先登录注册