如何查询文档使用数组中嵌套类型的两个对象?

时间:2018-04-28 13:34:50

标签: elasticsearch elasticsearch-5

我有这样的文件:

{
    "name": "Secret",
    "tags": [
        {
            { "key": "Project" },
            { "value": "X"}
        },
        {
            { "key": "Manager" },
            { "value": "David"}
        }
    ]
}

tags类型是嵌套类型。

我使用bool查询搜索文档有两个特定的标签:

{
"query": {
    "nested": {
        "path": "tags",
        "query": {
            "bool": {
                "must": [
                    { "match" : { "tags.key": "Project"}},
                    { "match" : { "tags.value": "X"}}
                ],
                "must": [
                    { "match" : { "tags.key": "Manager"}},
                    { "match" : { "tags.value": "David"}}
                ]
            }
        }
    }
}

但它不起作用:

{
    "took" : 4,
      "timed_out" : false,
      "_shards" : {
      "total" : 10,
      "successful" : 10,
      "skipped" : 0,
      "failed" : 0
    },
    "hits" : {
      "total" : 0,
      "max_score" : null,
      "hits" : [ ]
    }
}

有什么不对吗?

0 个答案:

没有答案