我有一个嵌套数据类型的查询,并希望返回嵌套数据类型的stats聚合(由查询过滤)。这是代码:
GET dan-created/_search
{
"_source" : ["m_iID", "m_iYear"],
"query": {
"nested": {
"path": "m_PeopleList",
"query": {
"match": {
"m_PeopleList.name": "Daniel"
}
},
"inner_hits" : {}
}
},
"aggregations" : {
"people" : {
"nested" : {
"path" : "m_PeopleList"
},
"aggregations" : {
"averageDist": {
"stats" : {
"field":"m_PeopleList.value"
}
}
}
}
}
}
返回的统计信息是针对整个索引的,但我希望它们只返回上面查询中的匹配项。我在其他地方看过这个例子,但没有看到最新版本的elasticsearch,我似乎无法让它们起作用。
谢谢, 丹尼尔
答案 0 :(得分:0)
您可以使用filter aggregation
"aggregations" : {
"people" : {
"nested" : {
"path" : "m_PeopleList"
},
"aggregations" : {
"myFilter": {
"filter" : { "match": { "m_PeopleList.name": "Daniel" } },
"aggregations": {
"averageDist": {
"stats" : {
"field":"m_PeopleList.value"
}
}
}
}
}
}
}