gpt4 book ai didi

elasticsearch - 在ElasticSearch中聚合嵌套对象

转载 作者:行者123 更新时间:2023-12-03 01:40:53 27 4
gpt4 key购买 nike

假设我们有这个文件:

{
"Article" : [
{
"id" : 12
"title" : "An article title",
"categories" : [1,3,5,7],
"tag" : ["elasticsearch", "symfony",'Obtao'],
"author" : [
{
"firstname" : "Francois",
"surname": "francoisg",
"id" : 18
},
{
"firstname" : "Gregory",
"surname" : "gregquat"
"id" : "2"
}
]
}
},
{
"id" : 13
"title" : "A second article title",
"categories" : [1,7],
"tag" : ["elasticsearch", "symfony",'Obtao'],
"author" : [
{
"firstname" : "Gregory",
"surname" : "gregquat",
"id" : "2"
}
]
}
}

如何按ID查找所有唯一作者?什么是正确的查询?我需要返回所有唯一作者(“author.id”)

感谢帮助。

最佳答案

首先,应为nested字段设置author类型的映射。
其次,正如@Taras_Kohut所述,在重新索引整个数据之后,您可以执行以下操作:

{
"size": 0,
"aggregations": {
"records": {
"nested": {
"path": "author"
},
"aggregations": {
"ids": {
"terms": {
"field": "author.id"
}
}
}
}
}
}

参见 Nested Aggregation

关于elasticsearch - 在ElasticSearch中聚合嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47733516/

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