gpt4 book ai didi

elasticsearch - 用Elasticsearch进行子聚合

转载 作者:行者123 更新时间:2023-12-02 22:23:29 26 4
gpt4 key购买 nike

我的索引包含像这样的文档

{
"members": [{
"name": "James",
"language": "english"
}],
"signupdate": "1/1/2016"
}

我想使用子聚合来获取顶级语言及其注册日期直方图

这就是我所拥有的,但是结果子聚合为空[]
{
"aggs": {
"members": {
"nested": { "path": "members" },
"aggs": {
"language": {
"terms": {
"field": "members.language"
},
"aggs": {
"date": {
"date_histogram": {
"field": "signupdate",
"interval": "month"
}
}
}
}
}
}
}
}

flex 搜索甚至可以做到吗?

最佳答案

这是正确的聚合查询(提示:您需要使用 reverse_nested 从嵌套上下文中跳回到父级上下文中)

{
"aggs": {
"members": {
"nested": {
"path": "members"
},
"aggs": {
"language": {
"terms": {
"field": "members.language"
},
"aggs": {
"parent": {
"reverse_nested": {},
"aggs": {
"date": {
"date_histogram": {
"field": "signupdate",
"interval": "month"
}
}
}
}
}
}
}
}
}
}

关于elasticsearch - 用Elasticsearch进行子聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41295606/

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