# How to tell the "exists"-query to include empty fields

**URL:** https://discuss.elastic.co/t/how-to-tell-the-exists-query-to-include-empty-fields/163221
**Category:** Elasticsearch
**Created:** [January 7, 2019, 2:21pm UTC](https://discuss.elastic.co/t/how-to-tell-the-exists-query-to-include-empty-fields/163221 "2019-01-07T14:21:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cherry-wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cherry-wave/32/32696_2.png) [@cherry-wave](https://discuss.elastic.co/u/cherry-wave)
#### Post date: [January 7, 2019, 2:21pm UTC](https://discuss.elastic.co/t/how-to-tell-the-exists-query-to-include-empty-fields/163221/1 "2019-01-07T14:21:18Z")

</div>

Hello =)

I am using elastic search in version 5.6.4 and want to find entries where a field "tags" is existent. One rule of this query is "At least one non- `null` value is required." However, I want to treat empty fields as existent too. Here is a tiny example:

```
DELETE days

POST days/day
{
  "name": "monday"
}

POST days/day
{
  "tags": []
}

POST days/day
{
  "tags": [""]
}

POST days/day
{
  "tags": ["sunny"]
}

GET days/_search
{
  "query": {
    "exists": {
      "field": "tags"
    }
  }
}

```

So basically I want to find all entries except the first one, where this field is really not there.

Is there another query to achieve this? Because I find it a bit odd to have empty strings as placeholders.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 7, 2019, 2:42pm UTC](https://discuss.elastic.co/t/how-to-tell-the-exists-query-to-include-empty-fields/163221/2 "2019-01-07T14:42:54Z")

</div>

My advice is to compute this at index time.  
You can use an ingest Script for example and compute a isEmpty field which you can index within your document.  
Or a tag\_size number field..

---

<div class="post-metadata">

### Author: ![cherry-wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cherry-wave/32/32696_2.png) [@cherry-wave](https://discuss.elastic.co/u/cherry-wave)
#### Post date: [January 7, 2019, 3:07pm UTC](https://discuss.elastic.co/t/how-to-tell-the-exists-query-to-include-empty-fields/163221/3 "2019-01-07T15:07:13Z")

</div>

Thank you, I am always thinking too complicated. Your ideas led me to the following solution: I fill those fields by myself and on this spot, I add a boolean saying if this field exists or not, lol \>\_\> Silly me.

---

<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: [February 4, 2019, 3:07pm UTC](https://discuss.elastic.co/t/how-to-tell-the-exists-query-to-include-empty-fields/163221/4 "2019-02-04T15:07:27Z")

</div>

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