【问题标题】:ElasticSearch 5: Search nested fieldElasticSearch 5:搜索嵌套字段
【发布时间】:2018-02-06 20:41:30
【问题描述】:

我有以下文档,它已被 ElasticSearch 5.5 编入索引

{
    "dept_id": "DP123",
    "related_depts": [
        {
            "id": "DP222",
            "roles": [
                {
                    "status": null,
                    "persons": [
                        {
                            "id": "P123",
                            "roles": [
                                {
                                    "status": null
                                }
                            ]
                        },

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

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

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

我收到以下错误。

failed to find nested object under path [related_depts.roles.persons]

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    您的所有对象都在数组中。
    因此,您需要搜索每个索引的第一个索引:

    related_depts[0].roles[0].persons[0]
    

    希望这会有所帮助!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    相关资源
    最近更新 更多