【问题标题】:Custom Histogram aggregation in ElasticsearchElasticsearch 中的自定义直方图聚合
【发布时间】:2020-04-15 18:28:51
【问题描述】:

我有以下结构的索引

item_id: unique item id
sale_date: date of the date
price: price of the sale wrt the date

我想创建每件商品的最新销售价格的直方图。聚合词 item_id 和最后一个或最新的直方图 price

我的第一选择是 term 聚合 item_id 并从 top_hits size 1 order sale_date desc 中选择 price 并在 python 端创建直方图。

但是。 因为数据在一个月的数百万条记录中。及时下载所有sources进行直方图是不可行的。

注意:有些商品每天出售,有些则在不同的时间间隔出售。这使得仅选择最新的sale_date

变得很棘手

更新

输入:基于商品的销售时间序列数据。

输出:项目数量的直方图位于特定价格桶中,以最新信息为准

【问题讨论】:

    标签: python elasticsearch histogram elasticsearch-aggregation


    【解决方案1】:

    我转过身来,我用过类似的情况,你可以使用max aggs 和date 类型,你可以基于嵌套aggs 值的order 聚合,就像:

    "aggs": {
      "item ID": {
        "terms": {
          "field": "item_id",
          "size": 10000
        },
        "aggs": {
          "price": {
            "terms": {
              "field": "price",
              "size": 1,
              "order": {
                "sale_date": "desc"
              }
            },
            "aggs": {
              "sale_date": {
                "max": {
                  "field": "sale_date"
                }
              }
            }
          }
        }
      }
    }
    

    我希望这会对你有所帮助,如果它适用于你,我希望你通知我。

    【讨论】:

    • 我认为你没有理解这个问题。这不是我期望的结果。目标是从 x 轴中的 selling price 项和 y 轴计数 item_id 的直方图聚合
    猜你喜欢
    • 1970-01-01
    • 2016-03-31
    • 1970-01-01
    • 2022-07-13
    • 1970-01-01
    • 2015-01-30
    • 2020-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多