您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch平均聚合字段的缺省配置missing
发布时间:2021-09-02 21:04:41编辑:雪饮阅读()
在上篇了解了elasticSearch的平均聚合请求,那么对于像是elasticSearch这种非mysql那种标准关系型数据库来说,每个数据的字段并非都一样,比如上篇中提到对于schools中的文档中的fees字段求平均值,那么某些文档中就步存在该字段,此时我们可以配置当某个文档步存在待求平均值的字段时候的缺省值。
像是下面这个请求中就讲缺省的fees字段默认配置为1000
一个请求如:
请求正文:
{
"aggs":{
"avg_fees":{
"avg":{
"field":"fees",
"missing":1000
}
}
}
}
响应正文:
{
"took": 1100,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 5,
"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"
}
},
{
"_index": "schools",
"_type": "school",
"_id": "5",
"_score": 1.0,
"_source": {
"name": "Central School",
"description": "ICSE",
"street": "West End",
"city": "Meerut",
"state": "UP",
"zip": "250002",
"location": [
28.9926174,
77.692485
],
"tags": [
"fully computerized"
],
"rating": "4.5"
}
}
]
},
"aggregations": {
"avg_fees": {
"value": 3300.8
}
}
}
关键字词:elasticSearch,聚合,平均,missing,缺省