对象数组上的聚合
我的弹性中有以下数据。
{
...someData,
languages: [
{
language:{_id: 1, name:"English"}
},
{
language:{_id: 2, name:"Arabic"}
}
]
}
但是当我使用此查询聚合数据时,
aggs: {
languages: {
terms: {
field: "languages.language._id.keyword",
size: 50
},
aggs: {
value: {
terms: {
field: "languages.language.name.keyword"
}
}
}
}
}
我将获得带有 2 个阿拉伯语和英语桶的英语 ID 阿拉伯语 id 也是如此,因为从技术上讲它包含在那里。
有没有办法只返回我需要的对象的数量?
谢谢
I have the following data in my elastic.
{
...someData,
languages: [
{
language:{_id: 1, name:"English"}
},
{
language:{_id: 2, name:"Arabic"}
}
]
}
But when I aggregate the data using this query
aggs: {
languages: {
terms: {
field: "languages.language._id.keyword",
size: 50
},
aggs: {
value: {
terms: {
field: "languages.language.name.keyword"
}
}
}
}
}
I will get the English id with 2 buckets for Arabic and English
and same for Arabic id, because technically its included there.
Is there a way to return only the count of the object I need?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将
languages
字段定义为嵌套,以便对数组的各个元素应用聚合。配置的嵌套字段:
示例文档索引:
示例聚合查询:
结果:
You need to define
languages
field as nested for applying aggregation on individual element of array.Configured Nested field:
Sample document index:
Sample Aggregation Query:
Result:
您是否尝试过此操作:
您不需要其他聚合。您可以使用
doc_count
键访问Did you try this :
You do not need the other aggregation. You can access using the
doc_count
key