[英]Aggregate nested objects in ElasticSearch
Let's say we have this document: 假设我们有此文档:
{
"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"
}
]
}
}
How can I find all unique authors by id? 如何按ID查找所有唯一作者? What is the proper query?
什么是正确的查询? I need to return all unique authors ("author.id")
我需要返回所有唯一作者(“ author.id”)
Thanks for help. 感谢帮助。
First, you should set your mapping with nested
type for the field author
. 首先,您应该为字段
author
设置nested
类型的映射。 Second, as @Taras_Kohut mentioned, and after you re-indexed the entire data, you can do: 第二,正如@Taras_Kohut所述,在重新索引整个数据之后,您可以执行以下操作:
{
"size": 0,
"aggregations": {
"records": {
"nested": {
"path": "author"
},
"aggregations": {
"ids": {
"terms": {
"field": "author.id"
}
}
}
}
}
}
See Nested Aggregation 请参阅嵌套聚合
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.