针对启用了include_in_parent的Elasticsearch中的嵌套字段的嵌套查询与非嵌套查询

时间:2019-12-18 14:03:45

标签: elasticsearch nested elasticsearch-5

我正在使用Elasticsearch 5.1.1。 我有以下部分映射的索引:

{
"properties": {
    "machine": {
        "properties": {
            "name": {
                "type": "keyword"
            },
            "networkInterface": {
                "type": "nested",
                "include_in_parent": true,
                "macAddress": {
                    "type": "keyword"
                },
                "name": {
                    "type": "text"
                }
            }
        }
    }
}

}

我正在尝试查找具有至少一个非null macAddress接口的计算机。 尝试以下查询类型:

非嵌套查询:

    {
    "bool": {
        "must_not": [
            {
                "bool": {
                    "must_not": [
                        {
                            "exists": {
                                "field": "networkInterface.macAddress",
                                "boost": 1
                            }
                        }
                    ],
                    "disable_coord": false,
                    "adjust_pure_negative": true,
                    "boost": 1
                }
            }
        ],
        "disable_coord": false,
        "adjust_pure_negative": true,
        "boost": 1
    }
}

嵌套查询:

    {
  "query":{
    "bool":{
      "must_not":[
        {
          "nested":{
            "query":{
              "bool":{
                "must_not":[
                  {
                    "exists":{
                      "field":"networkInterface.macAddress",
                      "boost":1
                    }
                  }
                ],
                "disable_coord":false,
                "adjust_pure_negative":true,
                "boost":1
              }
            },
            "path":"networkInterface",
            "ignore_unmapped":false,
            "score_mode":"none",
            "boost":1
          }
        }
      ],
      "disable_coord":false,
      "adjust_pure_negative":true,
      "boost":1
    }
  }
}

我有一个具有3个网络接口的机器文档,如下所示:

[
  {
    "name":"x",
    "macAddress":"<mac-add1>"
  },
  {
    "name":"y",
    "macAddress":null
  },
  {
    "name":"z",
    "macAddress":"<mac-addr2>"
  }
]

对于第一个查询,它返回机器。但是第二个却没有。

是因为启用了include_in_parent吗? 还是我不了解针对嵌套字段的嵌套查询和非嵌套查询如何工作? 还是嵌套查询不正确?

0 个答案:

没有答案