首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ElasticSearch 5:搜索嵌套字段

ElasticSearch 5:搜索嵌套字段
EN

Stack Overflow用户
提问于 2018-02-06 20:41:30
回答 1查看 32关注 0票数 0

我有以下文档,并将其编入ElasticSearch 5.5

代码语言:javascript
复制
{
    "dept_id": "DP123",
    "related_depts": [
        {
            "id": "DP222",
            "roles": [
                {
                    "status": null,
                    "persons": [
                        {
                            "id": "P123",
                            "roles": [
                                {
                                    "status": null
                                }
                            ]
                        },

                        {
                            "id": "P124",
                            "roles": [
                                {
                                    "status": null
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

现在,我想搜索所有具有persons id=P123的文档,我使用以下命令进行搜索。

代码语言:javascript
复制
curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
{
     "query": {
        "nested" : {
            "path" : "related_depts.roles.persons",
            "query" : {
                "match" : {
                    "id": "P123"
                }
            }
        }
    }
}
'

我得到了这个错误。

代码语言:javascript
复制
failed to find nested object under path [related_depts.roles.persons]
EN

回答 1

Stack Overflow用户

发布于 2018-02-06 20:46:28

所有的对象都在数组中。

因此,您需要搜索每个索引的第一个索引:

代码语言:javascript
复制
related_depts[0].roles[0].persons[0]

希望这能有所帮助!

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48651624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档