postman es 聚合查询
时间: 2023-11-22 13:50:59 浏览: 127
以下是使用Postman进行Elasticsearch聚合查询的步骤:
1.打开Postman,导入Elasticsearch的请求集合。
2.在请求集合中找到“Aggregations”文件夹,选择一个聚合查询请求。
3.在请求的Body中,填写聚合查询的参数,例如:
```
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state.keyword"
},
"aggs": {
"average_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
```
4.点击“Send”按钮,发送请求并等待响应。
5.在响应结果中,可以看到聚合查询的结果,例如:
```
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1000,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"group_by_state": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "CA",
"doc_count": 250,
"average_price": {
"value": 100.0
}
},
{
"key": "NY",
"doc_count": 250,
"average_price": {
"value": 200.0
}
},
{
"key": "TX",
"doc_count": 250,
"average_price": {
"value": 150.0
}
},
{
"key": "FL",
"doc_count": 250,
"average_price": {
"value": 120.0
}
}
]
}
}
}
```
6.在响应结果中,可以看到聚合查询的结果,例如上述结果中的“group_by_state”聚合查询结果,它将数据按照“state.keyword”字段进行分组,并计算每组的“price”字段的平均值。
阅读全文