1.请求方式:GET
2.请求URL:
http://127.0.0.1:9200/shopping/_search
3.请求参数:
(1)分组
{ "aggs" : { // 聚合操作 "price_group" : { // 统计结果名称 "terms" : { // 分组 "field" : "price" // 分组字段 } } }, "size": 0 }
(2)求平均值
{ "aggs" : { // 聚合操作 "price_avg" : { // 统计结果名称 "avg" : { // 求平均值 "field" : "price" // 求平均值字段 } } }, "size": 0 }
4. 响应信息:
(1) 分组
{ "took": 147, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 9, "relation": "eq" }, "max_score": null, "hits": [] }, "aggregations": { "price_group": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": 9999.0, "doc_count": 3 }, { "key": 2999.0, "doc_count": 1 }, { "key": 3999.0, "doc_count": 1 }, { "key": 4999.0, "doc_count": 1 }, { "key": 5999.0, "doc_count": 1 }, { "key": 6999.0, "doc_count": 1 }, { "key": 8999.0, "doc_count": 1 } ] } } }
(2)求平均值
{ "took": 1, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 9, "relation": "eq" }, "max_score": null, "hits": [] }, "aggregations": { "price_avg": { "value": 7110.111111111111 } } }