【问题标题】:Sorting percentiles aggregation with NaN values使用 NaN 值对百分位数聚合进行排序
【发布时间】:2019-01-07 16:09:42
【问题描述】:

我正在使用 ElasticSearch 2.3.3 并且我有以下聚合:

"aggregations": {
        "mainBreakdown": {
            "terms": {
                "field": "location_i",
                "size": 10,
                "order": [
                    {
                        "comments>medianTime.50": "asc"
                    }
                ]
            },
            "aggregations": {
                "comments": {
                    "filter": {
                        "term": {
                            "type_i": 120
                        }
                    },
                    "aggregations": {
                        "medianTime": {
                            "percentiles": {
                                "field": "time_l",
                                "percents": [
                                    50.0
                                ]
                            }
                        }
                    }
                }
            }
        }
    }

为了更好地理解,我在字段名称中添加了一个后缀,它告诉字段映射:

  • _i = 整数
  • _l = long(时间戳)

聚合响应是:

"aggregations": {
    "mainBreakdown": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": 100,
          "doc_count": 2,
          "comments": {
            "doc_count": 1,
            "medianTime": {
              "values": {
                "50.0": 20113
              }
            }
          }
        },
        {
          "key": 121,
          "doc_count": 14,
          "comments": {
            "doc_count": 0,
            "medianTime": {
              "values": {
                "50.0": "NaN"
              }
            }
          }
        }
      ]
    }
}

我的问题是 medianTime 聚合,有时具有 NaN 的值,因为父聚合 comments 有 0 个匹配的文档,然后带有 NaN 的结果将始终在两个“asc”上都是最后一个和“desc”顺序。
我尝试在percentiles 聚合中添加"missing": 0,但它仍然返回NaN

你能帮我按中值时间对我的存储桶进行排序,当它是“asc”时,NaN 值将是第一个,而当它的“desc”时它们将是最后一个?

【问题讨论】:

    标签: elasticsearch nan percentile elasticsearch-aggregation


    【解决方案1】:

    NaN 不是数字,所以它们总是排在最后。
    在对 elasticsearch github 进行了简短讨论后,我们决定了它处理 NaN 的适当方式。
    https://github.com/elastic/elasticsearch/issues/36402

    【讨论】:

      猜你喜欢
      • 2021-04-11
      • 2021-01-04
      • 2014-02-06
      • 2023-03-06
      • 2019-07-12
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      • 2019-12-26
      相关资源
      最近更新 更多