文章目录世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
- stats_bucket
- 作用
- 配置项
- 使用
- 索引
- 统计
- bucket的常规聚合统计
- buckets_path
- bucket路径,必填
- gap_policy
- 间隙策略,默认skip
- format
- 返回值格式,默认null
DELETE /stats_bucket_test PUT /stats_bucket_test { "mappings" : { "properties" : { "type" : {"type" : "integer"}, "num" : {"type" : "integer"}, "date" : {"type" : "date"} } } } POST /stats_bucket_test/_bulk {"index" : {"_id" : 1}} {"type" : 1, "num" : 40, "date" : "2001-01-10"} {"index" : {"_id" : 2}} {"type" : 2, "num" : 45, "date" : "2001-01-20"} {"index" : {"_id" : 3}} {"type" : 1, "num" : 58, "date" : "2001-02-10"} {"index" : {"_id" : 4}} {"type" : 2, "num" : 99, "date" : "2001-03-20"} {"index" : {"_id" : 5}} {"type" : 1, "num" : 66, "date" : "2001-04-21"} {"index" : {"_id" : 6}} {"type" : 1, "num" : 68, "date" : "2001-05-21"}统计
GET /stats_bucket_test/_search { "size" : 0, "aggs" : { "month_aggs" : { "date_histogram": { "field" : "date", "calendar_interval" : "month" }, "aggs" : { "sum_aggs" : { "sum": { "field": "num" } } } }, "stats_bucket_aggs" : { "stats_bucket": { "buckets_path": "month_aggs>sum_aggs" } } } }
- 返回结果
{ "took" : 14, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 6, "relation" : "eq" }, "max_score" : null, "hits" : [ ] }, "aggregations" : { "month_aggs" : { "buckets" : [ { "key_as_string" : "2001-01-01T00:00:00.000Z", "key" : 978307200000, "doc_count" : 2, "sum_aggs" : { "value" : 85.0 } }, { "key_as_string" : "2001-02-01T00:00:00.000Z", "key" : 980985600000, "doc_count" : 1, "sum_aggs" : { "value" : 58.0 } }, { "key_as_string" : "2001-03-01T00:00:00.000Z", "key" : 983404800000, "doc_count" : 1, "sum_aggs" : { "value" : 99.0 } }, { "key_as_string" : "2001-04-01T00:00:00.000Z", "key" : 986083200000, "doc_count" : 1, "sum_aggs" : { "value" : 66.0 } }, { "key_as_string" : "2001-05-01T00:00:00.000Z", "key" : 988675200000, "doc_count" : 1, "sum_aggs" : { "value" : 68.0 } } ] }, "stats_bucket_aggs" : { "count" : 5, "min" : 58.0, "max" : 99.0, "avg" : 75.2, "sum" : 376.0 } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)