我有一个基准指数,包含来自医院病房的数据,我想知道每周病房位置的药物使用情况。
现在的问题是,当我选择一周的数据时,具有多个病房的位置的人口将被计算错误。我想知道那一周某个地点的平均人口数。该地点的人口是该地区内病房人口的总和
{
"_index": "development_benchmark",
"_type": "score",
"_id": "3147603",
"_score": null,
"_source": {
"id": 3147603,
"score": 86,
"amount": 1758.7,
"population": 2045,
"date": "2018-01-12T03:00:00+01:00",
"benchmark_id": 10,
"ward": {
"id": 24170,
"ward_types": [
3
]
},
"location_id": 24285,
"cluster_id": 72997
}
}
我的查询如下:
GET development_benchmark/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"date": {
"gte": "2017-12-20",
"lte": "2017-12-20"
}
}
}
]
}
},
"aggs": {
"benchmarks": {
"terms": {
"field": "benchmark_id",
"size": 100
},
"aggs": {
"clusterScore": {
"filter": {
"bool": {
"must": [
{
"term": {
"cluster_id": 72997
}
}
]
}
},
"aggs": {
"amount": {
"sum": {
"field": "amount"
}
},
"population": {
"sum": {
"field": "population"
}
},
"locations": {
"terms": {
"field": "location_id",
"size": 1000
},
"aggs": {
"amount": {
"sum": {
"field": "amount"
}
},
"population": {
"sum": {
"field": "population"
}
}
}
}
}
}
}
}
}
答案 0 :(得分:0)
答案是汇总地点,如:
"locations" => [
"terms" => [
"field" => "location_id",
"size" => 1000
],
"aggs" => [
"wards" => [
"terms" => [
"field" => "ward.id",
"size" => 1000
],
"aggs" => [
"amount" => [
"avg" => [
"field" => "amount"
]
],
"population" => [
"avg" => [
"field" => "population"
]
]
]
],
"amount" => [
"sum_bucket" => [
"buckets_path" => "wards>amount"
]
],
"population" => [
"sum_bucket" => [
"buckets_path" => "wards>population"
]
]
]
]
]
计算所选时间内病房的平均人口。然后总结每个位置的所有平均病房人口