Elasticsearch错误语法:在[桶]中找到两个聚合类型定义:[composite]和[sum_bucket]

发布于 2025-02-11 09:05:36 字数 1628 浏览 1 评论 0原文

我使用Elasticsearch 6.1并在聚合中使用复合和sum_bucket时会出现错误。

这给我带来了一个错误:

原因:在[my_buckets_sale]中找到两个聚合类型定义]:[composite]和[sum_monthly_sales] 这是我想做的示例:

{
...
                "size": 0,
                "aggs" : {
                    "my_buckets_sale" : {
                        composite: {
                        size    : 4,
                                sources : [
                                    {
                                        date : {
                                            date_histogram : {
                                                field    : '@timestamp',
                                                interval : 'day',
                                            },
                                        },
                                    },
                                   },
                                ],
                        }
                        "date_histogram" : {
                            "field" : "date",
                            "interval" : "month"
                        },
                    "aggs": {
                        "sales": {
                            "sum": {
                                "field": "price"
                            }
                        }
                    }
                    "sum_monthly_sales": {
                        "sum_bucket": {
                            "buckets_path": "my_buckets_sale>sales" 
                        }
                    }
                 }
               },
            }

有人知道如何完成所有桶的总和,以保持我的复合材料?

I use ElasticSearch 6.1 and get an error when I try to use composite and sum_bucket together in my aggregation.

It get me an error:

Reason: Found two aggregation type definitions in [my_buckets_sale]: [composite] and [sum_monthly_sales]",
Here is a example of what I want to do :

{
...
                "size": 0,
                "aggs" : {
                    "my_buckets_sale" : {
                        composite: {
                        size    : 4,
                                sources : [
                                    {
                                        date : {
                                            date_histogram : {
                                                field    : '@timestamp',
                                                interval : 'day',
                                            },
                                        },
                                    },
                                   },
                                ],
                        }
                        "date_histogram" : {
                            "field" : "date",
                            "interval" : "month"
                        },
                    "aggs": {
                        "sales": {
                            "sum": {
                                "field": "price"
                            }
                        }
                    }
                    "sum_monthly_sales": {
                        "sum_bucket": {
                            "buckets_path": "my_buckets_sale>sales" 
                        }
                    }
                 }
               },
            }

Does anyone know how to do the sum of all the buckets, with keeping my composite ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉月流沐 2025-02-18 09:05:36

您想做的是保持复合汇总,同时仍然每月获得所有销售的总和?
这样的结构:

{
   "size" : 0,
   "aggs" : {
      "my_bucket_sale" : {
           "composite" : {...},
           "aggs" : {
              "sum_of_sales" : {
                  "sum" : {"field" : "price"}
              }
          }
      },
      "my_bucket_months" : {
          "date_histogram" : {"field" : "date", "interval" : "month"},
          "aggs" : {
              "sum_of_monthly_sales" : {
                  "sum" : {"field" : "price"}
              }
          }
      }
   }
}

只需在日期直方图上创建一个子聚集,就可以根据需要为您提供总和。无需将其与复合加剧混合。

谢谢。

What you want to do is keep the composite aggregation as it is while still getting the sum of all the sales in every month?
Structure like this:

{
   "size" : 0,
   "aggs" : {
      "my_bucket_sale" : {
           "composite" : {...},
           "aggs" : {
              "sum_of_sales" : {
                  "sum" : {"field" : "price"}
              }
          }
      },
      "my_bucket_months" : {
          "date_histogram" : {"field" : "date", "interval" : "month"},
          "aggs" : {
              "sum_of_monthly_sales" : {
                  "sum" : {"field" : "price"}
              }
          }
      }
   }
}

Just create a subaggregation on the date histogram to give you the sum as you required. There is no need to mix this with the composite aggrgation.

THanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文