# Check empty string in nested attribute

**URL:** https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477
**Category:** Elasticsearch
**Created:** [February 1, 2017, 8:09am UTC](https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477 "2017-02-01T08:09:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dmitriiPopov](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dmitriiPopov](https://discuss.elastic.co/u/dmitriiPopov)
#### Post date: [February 1, 2017, 8:09am UTC](https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477/1 "2017-02-01T08:09:30Z")

</div>

How can I get all records from index with empty string value (`"field":""`)?  
Example of needed document:

```auto
   {
      "post_id":"56565656",
      "data" : {
              "owner_id" : "121213123",
              "text" : ""
      }
    }

```

I tried to use it:

```auto
curl 'localhost:9200/posts/_count?pretty' -d '
{
  "query": {
    "filtered": {
      "filter": {
            "nested" : {
              "path" : "data",
              "filter": {
                  "bool": {
                    "must": [
                        {"term" : { "data.text" : "" }}
                    ]
                  }
          }
        }
      }
    }
  }
}'

```

BUT it doesn't work!  
Help me, please.

---

<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: [February 1, 2017, 8:27am UTC](https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477/2 "2017-02-01T08:27:11Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

Have a look at `exists` query: [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html)

---

<div class="post-metadata">

### Author: ![dmitriiPopov](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dmitriiPopov](https://discuss.elastic.co/u/dmitriiPopov)
#### Post date: [February 1, 2017, 9:14am UTC](https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477/3 "2017-02-01T09:14:41Z")

</div>

It didn't help.  
`Exists` query finds records with "" value ((  
This information is written in documentation as well.

I need to exclude records with empty-string value or find another.

---

<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: [February 1, 2017, 9:44am UTC](https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477/4 "2017-02-01T09:44:05Z")

</div>

so wrap the `exists` query in a `must_not` clause of a `bool` query.

Would that work for you?

---

<div class="post-metadata">

### Author: ![dmitriiPopov](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dmitriiPopov](https://discuss.elastic.co/u/dmitriiPopov)
#### Post date: [February 1, 2017, 10:17am UTC](https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477/5 "2017-02-01T10:17:38Z")

</div>

By this case records has been found with `"text":null` value.  
BUT I need to find records with `"text":""`

---

<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: [February 1, 2017, 10:31am UTC](https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477/6 "2017-02-01T10:31:08Z")

</div>

I see.

So you need to reindex probably.

Or may be a script which reads the \_source stored field. But that will be slow.  
For a one time usage, that's probably fine. If this is something you need to run everytime, change your source documents.

You can use ingest BTW to do that transformation while reindexing.

---

<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: [March 1, 2017, 10:31am UTC](https://discuss.elastic.co/t/check-empty-string-in-nested-attribute/73477/7 "2017-03-01T10:31:38Z")

</div>

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