kolurbo
kolurbo

Reputation: 538

ElasticSearch missing and term query

I am trying to fetch documents where is missing field "topic.description" and match term "fundedUnder.programme": "ABC".

Mapping:

...
"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"
         }
    }
},
...

My Query looks like:

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

This query found nothing and that is wrong, because I have in indexes a lot of documents with fundedUnder.programme == "ABC" and with missing field topics.description.

Thanks in advance.

ElasticSearch version 1.7.5

Upvotes: 0

Views: 2315

Answers (1)

Aaron M. Eshbach
Aaron M. Eshbach

Reputation: 6510

I believe this should work:

EDIT: updated to use version 1.7 Query DSL

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

Upvotes: 1

Related Questions