elasticsearch ElasticSearch缺失和术语查询,elasticsearch,elasticsearch" /> elasticsearch ElasticSearch缺失和术语查询,elasticsearch,elasticsearch" />

elasticsearch ElasticSearch缺失和术语查询

elasticsearch ElasticSearch缺失和术语查询,elasticsearch,elasticsearch,我正在尝试获取缺少字段“topic.description”的文档,并匹配术语“fundedUnder.program”:“ABC” 映射: ... "fundedUnder": { "properties": { "programme": { "type": "string" }, "subprogramme": { "type": "string" } } }, "

我正在尝试获取缺少字段“topic.description”的文档,并匹配术语“fundedUnder.program”:“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" 
                }
            }   
          ]
        }
      }
    }
  }
}
这个查询没有发现任何错误,因为我在索引中有很多文档,它们的fundedUnder.program==“ABC”,并且缺少字段topics.description

提前谢谢


ElasticSearch 1.7.5版

我认为这应该是可行的:

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

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

@aaron-m-eshbach感谢您的回复,但它不起作用(“SearchPhaseExecutionException”)。我想这是因为弹性版本。@Joozty,对此很抱歉,我查看了1.7版文档并更新了我的答案。我没有权限对1.7服务器进行测试,所以我不是100%确定,但我认为它应该可以工作。@aaron-m-eshbach现在查询可以工作了,但它与我的查询相同。它什么也不返回。当我删除匹配fundedUnder.program的术语时,它会返回所有缺少字段的文档。@Joozty,您是否尝试了
Match
查询而不是
term
查询?我再次更新了示例。如果它仍然不起作用,你能试试不带过滤器的match或term子句,看看你是否至少能找到你的
程序='ABC'
结果吗?@aaron-m-eshbach非常感谢你。你帮了我很多。