多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# Max Bucket Aggregation 最大值桶聚合所定义的桶包含一组聚合指定度量的最大值,并且同时输出桶的键和值。指定的度量必须是数字并且这个聚合必须是多桶聚合。 ### 语法 `max_bucket` 聚合结构如下: | `{` `"max_bucket"``: {` `"buckets_path"``: ``"the_sum"` `}` `}` | `max_bucket` 参数如下: | 参数名称 | 描述 | 是否必填 | 默认值 | | --- | --- | --- | --- | | buckets_path | 想要计算最大值的桶路径,点击 [the section called “`buckets_path` Syntax](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-aggregations-pipeline.html#buckets-path-syntax "buckets_path Syntaxedit")[edit](https://github.com/elastic/elasticsearch/edit/5.4/docs/reference/aggregations/pipeline.asciidoc "Edit this page on GitHub")”查看更多细节 | 必填 |   | | gap_policy | 当数据缺口出现时采用的策略,点击[the section called “Dealing with gaps in the data](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-aggregations-pipeline.html#gap-policy "Dealing with gaps in the dataedit")[edit](https://github.com/elastic/elasticsearch/edit/5.4/docs/reference/aggregations/pipeline.asciidoc "Edit this page on GitHub")”查看更多细节 | 可选 | skip | | format | 用于规范聚合输出值的格式 | 可选 | null | 以下代码段计算每月总销售额的最大值: | `POST ``/sales/_search` `{` `"size"``: 0,` `"aggs"` `: {` `"sales_per_month"` `: {` `"date_histogram"` `: {` `"field"` `: ``"date"``,` `"interval"` `: ``"month"` `},` `"aggs"``: {` `"sales"``: {` `"sum"``: {` `"field"``: ``"price"` `}` `}` `}` `},` `"max_monthly_sales"``: {` `"max_bucket"``: {` `"buckets_path"``: ``"sales_per_month>sales"` `#1` `}` `}` `}` `}` | | 1 | buckets_path指示这个max_bucket聚合是要得到sales_per_month日期直方图中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` `}` `},` `{` `"key_as_string"``: ``"2015/02/01 00:00:00"``,` `"key"``: 1422748800000,` `"doc_count"``: 2,` `"sales"``: {` `"value"``: 60.0` `}` `},` `{` `"key_as_string"``: ``"2015/03/01 00:00:00"``,` `"key"``: 1425168000000,` `"doc_count"``: 2,` `"sales"``: {` `"value"``: 375.0` `}` `}` `]` `},` `"max_monthly_sales"``: {` `"keys"``: [``"2015/01/01 00:00:00"``], ``#1` `"value"``: 550.0` `}` `}` `}` | | 1 | key是字符串数组,因为最大值可能存在于多个存储桶中 |