gpt4 book ai didi

elasticsearch - Elasticsearch范围嵌套聚合到查询

转载 作者:行者123 更新时间:2023-12-03 00:08:17 26 4
gpt4 key购买 nike

我有一个嵌套数据类型的查询,想返回嵌套数据类型的统计信息汇总(由查询过滤)。这是代码:

    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,而且我似乎无法使它们正常工作。

谢谢,
丹尼尔

最佳答案

您可以使用filter aggregation

"aggregations" : {
"people" : {
"nested" : {
"path" : "m_PeopleList"
},
"aggregations" : {
"myFilter": {
"filter" : { "match": { "m_PeopleList.name": "Daniel" } },
"aggregations": {
"averageDist": {
"stats" : {
"field":"m_PeopleList.value"
}
}
}
}
}
}
}

关于elasticsearch - Elasticsearch范围嵌套聚合到查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43186365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com