最小桶聚合
编辑最小桶聚合
编辑一种兄弟管道聚合,它识别兄弟聚合中具有指定指标最小值的桶,并输出该值的桶的键。
语法
编辑单独的min_bucket
聚合看起来像这样:
{ "min_bucket": { "buckets_path": "the_sum" } }
表 66. min_bucket
参数
参数名称 | 描述 | 是否必需 | 默认值 |
---|---|---|---|
|
我们要查找最小值的桶的路径(有关更多详细信息,请参见 |
是否必需 |
|
|
在数据中发现间隙时要应用的策略(有关更多详细信息,请参见处理数据中的间隙) |
可选 |
|
|
输出值的DecimalFormat 模式。如果指定,则格式化后的值将返回在聚合的 |
可选 |
|
以下代码段计算每月总sales
的最小值
resp = client.search( index="sales", size=0, aggs={ "sales_per_month": { "date_histogram": { "field": "date", "calendar_interval": "month" }, "aggs": { "sales": { "sum": { "field": "price" } } } }, "min_monthly_sales": { "min_bucket": { "buckets_path": "sales_per_month>sales" } } }, ) print(resp)
response = client.search( index: 'sales', body: { size: 0, aggregations: { sales_per_month: { date_histogram: { field: 'date', calendar_interval: 'month' }, aggregations: { sales: { sum: { field: 'price' } } } }, min_monthly_sales: { min_bucket: { buckets_path: 'sales_per_month>sales' } } } } ) puts response
const response = await client.search({ index: "sales", size: 0, aggs: { sales_per_month: { date_histogram: { field: "date", calendar_interval: "month", }, aggs: { sales: { sum: { field: "price", }, }, }, }, min_monthly_sales: { min_bucket: { buckets_path: "sales_per_month>sales", }, }, }, }); console.log(response);
POST /sales/_search { "size": 0, "aggs": { "sales_per_month": { "date_histogram": { "field": "date", "calendar_interval": "month" }, "aggs": { "sales": { "sum": { "field": "price" } } } }, "min_monthly_sales": { "min_bucket": { "buckets_path": "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 } } ] }, "min_monthly_sales": { "keys": ["2015/02/01 00:00:00"], "value": 60.0 } } }