ElasticSearch缺失和术语查询

时间:2018-01-21 12:41:19

标签: elasticsearch

我正在尝试提取缺少字段" topic.description" 的文档,并匹配字词" fundingUnder.programme":&#34 ; ABC"

映射:

...
"fundedUnder": {
    "properties": {
        "programme": {
            "type": "string"
        },
        "subprogramme": {
            "type": "string"
        }
    }
},
"topics": {
    "type": "nested",
    "include_in_parent": true,
    "properties": {
        "code": {
            "type": "string",
            "analyzer": "analyzer_keyword"
         },
         "description": {
             "type": "string",
             "analyzer": "analyzer_keyword"
         },
         "title": {
             "type": "string",
             "analyzer": "analyzer_keyword"
         }
    }
},
...

我的查询如下:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "missing": {
                "field": "topics.description"
              }
            },
            {
                "term": {
                    "fundedUnder.programme" : "ABC" 
                }
            }   
          ]
        }
      }
    }
  }
}

这个查询一无所获,这是错误的,因为我在索引中有很多文件,包括fundingUnder.programme ==" ABC"并缺少字段topic.description。

提前致谢。

ElasticSearch版本1.7.5

1 个答案:

答案 0 :(得分:1)

我相信这应该有效:

编辑:更新为使用版本1.7查询DSL

{
  "query": {
    "filtered": { 
      "query": {
        "match": { "fundedUnder.programme" : "ABC" }
      },
      "filter": {
        "missing": { "field": "topics.description" }
      }
    }
  }
}
相关问题