Check empty string in nested attribute

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

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

I tried to use it:

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.

Please format your code using </> icon as explained in this guide. 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

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.

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

Would that work for you?

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

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.

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