Thursday, January 19, 2017

Search documents having a specific field which is not null in Elasticsearch

To search documents having a specific field which is not null in Elasticsearch, do as follows:

http://localhost:9200/some_index/_search

{
  "query": {
    "constant_score": {
      "filter": {
        "exists": {
          "field" : "some_field.some_sub_field"
        }
      }
    }
  }
}

Reference:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html