企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Cumulative Sum Aggregation(累积汇总聚合) 父级管道聚合,计算父级直方图(或日期直方图)聚合中指定度量的累积和。指定的度量必须是数字,并且闭合min_doc_count直方图必须设置为0(默认为histogram聚合)。 ## Syntax(语法) cumulative_sum聚合看起来像这样: | `{` `"cumulative_sum"``: {` `"buckets_path"``: ``"the_sum"` `}` `}` | ## Table 10. `cumulative_sum` Parameters(Table 10.cumulative_sum参数) | 参数名称 | 描述 | 是否必须 | 默认值 | | --- | --- | --- | --- | | `buckets_path` | 我们希望找到的数据的桶的路径(相关详细信息,请参阅“buckets_path Syntax”一节) | 必须 |   | | `format` | 应用于此聚合的输出值的格式 | 可选 | `null` | 以下代码计算每月sales总额的累计总和: | `POST /sales/_search` `{` `"size"``: ``0``,` `"aggs"` `: {` `"sales_per_month"` `: {` `"date_histogram"` `: {` `"field"` `: ``"date"``,` `"interval"` `: ``"month"` `},` `"aggs"``: {` `"sales"``: {` `"sum"``: {` `"field"``: ``"price"` `}` `},` `"cumulative_sales"``: {` `"cumulative_sum"``: {` `"buckets_path"``: ``"sales"`     `#``1` `}` `}` `}` `}` `}` `}` | | 1 | buckets_path指示这个为cumulatice sum聚合,以使用累积和来输出sales聚合。 | 以下是响应信息: | `{` `"took"``: ``11``,` `"timed_out"``: ``false``,` `"_shards"``: ...,` `"hits"``: ...,` `"aggregations"``: {` `"sales_per_month"``: {` `"buckets"``: [` `{` `"key_as_string"``: ``"2015/01/01 00:00:00"``,` `"key"``: ``1420070400000``,` `"doc_count"``: ``3``,` `"sales"``: {` `"value"``: ``550.0` `},` `"cumulative_sales"``: {` `"value"``: ``550.0` `}` `},` `{` `"key_as_string"``: ``"2015/02/01 00:00:00"``,` `"key"``: ``1422748800000``,` `"doc_count"``: ``2``,` `"sales"``: {` `"value"``: ``60.0` `},` `"cumulative_sales"``: {` `"value"``: ``610.0` `}` `},` `{` `"key_as_string"``: ``"2015/03/01 00:00:00"``,` `"key"``: ``1425168000000``,` `"doc_count"``: ``2``,` `"sales"``: {` `"value"``: ``375.0` `},` `"cumulative_sales"``: {` `"value"``: ``985.0` `}` `}` `]` `}` `}` `}` |