【发布时间】:2021-01-20 23:32:21
【问题描述】:
如何在我的输出存储桶中添加一个名为“state_location,district_location”的新键。
我正在运行如下所示的聚合代码
"from": 0,
"size": 3,
"query": {
"bool": {}
},
"aggs": {
"State Location": {
"terms": {
"field": "block_location"
},
"aggs": {
"stakeholder Level": {
"terms": {
"field": "stakeholder_level"
},
"aggs": {
"stakeholder_category": {
"terms": {
"field": "stakeholder_category"
},
"aggs": {
"Coverage Calculation": {
"terms": {
"field": "stakeholder_name"
},
"aggs": {
"Total Hours": {
"sum": {
"field": "field_capacity_building_duration"
}
}
}
}
}
}
}
}
}
}
}
}
我尝试了ElasticSearch - How to display an additional field name in aggregation query 中解释的方法,但这不适用于多级聚合。我尝试了下面的代码
{
"from": 0,
"size": 0,
"query": {
"bool": {}
},
"aggs": {
"State Location": {
"terms": {
"field": "block_location"
},
"aggs": {
"state": {
"top_hits": {
"size": 1,
"_source": {
"includes": ["state_location","district_location"]
}
}
},
"aggs": {
"stakeholder Level": {
"terms": {
"field": "stakeholder_level"
},
"aggs": {
"stakeholder_category": {
"terms": {
"field": "stakeholder_category"
},
"aggs": {
"Coverage Calculation": {
"terms": {
"field": "stakeholder_name"
},
"aggs": {
"Total Hours": {
"sum": {
"field": "field_capacity_building_duration"
}
}
}
}
}
}
}
}
}
}
}
}
}
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation