【问题标题】:Elasticsearch Cardinality Aggregation giving wrong resultsElasticsearch 基数聚合给出错误的结果
【发布时间】:2016-10-18 14:41:59
【问题描述】:

两个聚合中的 PARTY_ID 计数应该相同。 在一种情况下,它是 3000,另一种情况下,它是所有不相等的值 (2675 + 244 + 41 + 6 + 2 = 2950 ) 的总和。 可能是什么原因?

GET /test/data/_search
{
   "size": 0,
   "aggs": {
      "ASSET_CLASS": {
         "terms": {
            "field": "ASSET_CLASS_WORST"
         },
         "aggs": {
            "ASSET_CLASS": {
               "cardinality": {
                  "field": "PARTY_ID"
               }
            }
         }
      },
      "Total count": {
         "cardinality": {
            "field": "PARTY_ID"
         }
      }
   }
}

结果:

{
   "took": 9,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 51891,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "Total count": {
         "value": 3000
      },
      "ASSET_CLASS": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "NPA",
               "doc_count": 49252,
               "ASSET_CLASS": {
                  "value": 2675
               }
            },
            {
               "key": "RESTRUCTURED",
               "doc_count": 2275,
               "ASSET_CLASS": {
                  "value": 244
               }
            },
            {
               "key": "SMA2",
               "doc_count": 308,
               "ASSET_CLASS": {
                  "value": 41
               }
            },
            {
               "key": "SMA1",
               "doc_count": 42,
               "ASSET_CLASS": {
                  "value": 6
               }
            },
            {
               "key": "SMA0",
               "doc_count": 14,
               "ASSET_CLASS": {
                  "value": 2
               }
            }
         ]
      }
   }
}

【问题讨论】:

    标签: elasticsearch aggregation elasticsearch-aggregation


    【解决方案1】:

    documentation for cardinality aggregation 的第一行内容为:

    计算近似值的单值指标聚合 不同值的计数。

    (强调我的)

    3000 次中有 10 次的误差远低于 1%,所以这是意料之中的。

    基数聚合使用HyperLogLog 演算的enhanced 版本,该演算具有诸如恒定内存复杂度和O(N) 时间复杂度等有趣的特性。

    如果您需要更精确的结果,请尝试为precision_threshold 参数设置更高的设置。

    GET /test/data/_search
    {
       "size": 0,
       "aggs": {
          "ASSET_CLASS": {
             "terms": {
                "field": "ASSET_CLASS_WORST"
             },
             "aggs": {
                "ASSET_CLASS": {
                   "cardinality": {
                      "field": "PARTY_ID",
                      "precision_threshold": 10000
                   }
                }
             }
          },
          "Total count": {
             "cardinality": {
                "field": "PARTY_ID",
                "precision_threshold": 10000
             }
          }
       }
    }
    

    【讨论】:

    • 感谢@Shadocko。你有任何关于这方面的性能统计数据
    • @James 不,您必须为您的特定设置运行基准测试。
    猜你喜欢
    • 2015-02-11
    • 1970-01-01
    • 2022-01-17
    • 2014-10-22
    • 2018-12-11
    • 1970-01-01
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多