您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch平均聚合平均数
发布时间:2021-09-02 20:33:38编辑:雪饮阅读()
在elasticSearch中此聚合用于获取聚合文档中存在的任何数字字段的平均值。 例如下面这个请求就是对文档中字段为fees的字段进行平均聚合,通俗点讲就是求平均数。
请求正文:
{
"aggs":{
"avg_fees":{"avg":{"field":"fees"}}
}
}
响应正文:
{
"took": 366,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "schools",
"_type": "school",
"_id": "1",
"_score": 1.0,
"_source": {
"name": "Central School4",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2004,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "3",
"_score": 1.0,
"_source": {
"name": "Central School",
"description": "ICSE",
"street": "West End",
"city": "Meerut",
"state": "UP",
"zip": "250002",
"location": [
28.9926174,
77.692485
],
"fees": 3500,
"tags": [
"fully computerized"
],
"rating": "4.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "2",
"_score": 1.0,
"_source": {
"name": "Saint Paul School",
"description": "ICSE Afiliation",
"street": "Dawarka",
"city": "Delhi",
"state": "Delhi",
"zip": "110075",
"location": [
28.5733056,
77.0122136
],
"fees": 5000,
"tags": [
"Good Faculty",
"Great Sports"
],
"rating": "4.5"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "4",
"_score": 1.0,
"_source": {
"name": "Saint Paul School",
"description": "ICSE Afiliation",
"street": "Dawarka",
"city": "Delhi",
"state": "Delhi",
"zip": "110075",
"location": [
28.5733056,
77.0122136
],
"fees": 5000,
"tags": [
"Good Faculty",
"Great Sports"
],
"rating": "4.5"
}
}
]
},
"aggregations": {
"avg_fees": {
"value": 3876.0
}
}
}
关键字词:elasticSearch,聚合,平均,avg