# Elastic search query to check if property is empty/non-empty

**URL:** <https://discuss.elastic.co/t/elastic-search-query-to-check-if-property-is-empty-non-empty/308290>\
**Category:** Elasticsearch\
**Created:** [June 27, 2022, 7:10pm UTC](https://discuss.elastic.co/t/elastic-search-query-to-check-if-property-is-empty-non-empty/308290 "2022-06-27T19:10:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newelastic](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@newelastic](https://discuss.elastic.co/u/newelastic)\
**Post date:** [June 27, 2022, 7:10pm UTC](https://discuss.elastic.co/t/elastic-search-query-to-check-if-property-is-empty-non-empty/308290/1 "2022-06-27T19:10:57Z")

</div>

Hello,

I was trying to find out all my documents which has property with empty value or non-empty value. The type of this property is "keyword". I'm using ES 6.8.1 version.

I couldn't find anything in the documentation to query for this scenario. Can someone help ?

---

<div class="post-metadata">

**Author:** ![newelastic](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@newelastic](https://discuss.elastic.co/u/newelastic)\
**Post date:** [June 27, 2022, 9:12pm UTC](https://discuss.elastic.co/t/elastic-search-query-to-check-if-property-is-empty-non-empty/308290/2 "2022-06-27T21:12:14Z")

</div>

After trying the must and filter properties, I was able to query the documents that has null/nullable values.

Posting the queries so anyone can find them useful

Query to fetch all the documents that has the property in the document

```auto
GET index_name/_count
{
  "query": {
    "bool": {
      "must": {
        "exists": { "field": "your document property name"}
        }
    }
  }
}

```

Query to fetch all the documents that have the property AND the property contains empty value

```auto
GET index_name/_count
{
  "query": {
    "bool": {
      "must": {
        "exists": { "field": "your document property name"}
        },
        "filter": {
          "term": {"your document property name": ""}
      }
    }
  }
}

```

Query to fetch all the documents that have the property AND the property contains NON-Empty value

```auto
GET index_name/_count
{
  "query": {
    "bool": {
      "must": {
        "exists": { "field": "your document property name"}
        },
        "must_not": {
          "term": {"your document property name": ""}
      }
    }
  }
}

```

Thank you !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 25, 2022, 9:12pm UTC](https://discuss.elastic.co/t/elastic-search-query-to-check-if-property-is-empty-non-empty/308290/3 "2022-07-25T21:12:16Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
