【问题标题】:how to get derivative aggregations on the simple count如何获得简单计数的导数聚合
【发布时间】:2023-03-06 18:11:01
【问题描述】:

使用 ES 2.3.3

我想使用Derivative Aggregation,但应该用来计算它的指标不是avgsum,它只是父直方图(sales_per_month)每个桶的原始doc_count .

我通过使用 stats agg 让它像这样工作:

"aggs" : {
    "sales_per_month" : {
        "date_histogram" : {
            "field" : "date",
            "interval" : "month"
        },
        "aggs": {
            "sales": {
                "stats": {
                    "field": "price"
                }
            },
            "sales_deriv": {
                "derivative": {
                    "buckets_path": "sales.count" 
                }
            }
        }
    }
}

这真的是这样做的方法还是我错过了一种更简单的方法?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    我认为没有比这更简单的了。它看起来不错,简单而优雅。

    【讨论】:

      【解决方案2】:

      没有必要仅仅为了引用count而定义一个嵌套的stats聚合。每个存储桶都有一个隐含的_count 属性,对应于doc_count,您可以在bucket_path 中使用。

      在您的示例中,您引用的是上下文父聚合,您只需引用 _count(即您已经在 sales_per_month 聚合的上下文中)。

      在您的具体情况下,您可以将其用作:

      "aggs": {
        "sales_per_month": {
          "date_histogram": {
            "field": "date",
            "interval": "month"
          },
          "aggs": {
            "sales_deriv": {
              "derivative": {
                "buckets_path": "_count"
              }
            }
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2019-03-24
        • 2019-07-19
        • 2022-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-15
        • 2021-08-22
        相关资源
        最近更新 更多