小编Cam*_*Cam的帖子

在Elasticsearch中使用date_histogram聚合计算嵌套字段的总和

我在使用 date_histogram 获取 Elasticsearch 中嵌套字段的总和时遇到困难,我希望有人能帮我一把。

我有一个如下所示的映射:

"client" : {
  // various irrelevant stuff here...

  "associated_transactions" : {
    "type" : "nested",
    "include_in_parent" : true,
    "properties" : {
      "amount" : {
        "type" : "double"
      },
      "effective_at" : {
        "type" : "date",
        "format" : "dateOptionalTime"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我试图获取一个 date_histogram,它显示所有客户按月的总收入 - 即一个时间序列,显示由 Associated_transactions. effective_date 确定的直方图中关联_transactions.amount 的总和。我尝试运行这个查询:

{
  "query": {
    // ...
  },
  "aggregations": {
    "revenue": {
      "date_histogram": {
        "interval": "month",
        "min_doc_count": 0,
        "field": "associated_transactions.effective_at"
      },
      "aggs": {
        "monthly_revenue": {
          "sum": {
            "field": …
Run Code Online (Sandbox Code Playgroud)

elasticsearch

5
推荐指数
1
解决办法
2861
查看次数

标签 统计

elasticsearch ×1