Filter documents that contain array with empty string

I've documents in Elasticsearch and I want to filter out the documents that contain an array of only empty strings or have nothing / empty array.

#doc 1
{
  "_index": "my-index-000001",
  "_type": "_doc",
  "_id": "0",
  "_source": {
    "doc":{
    	"field": ["",""]
    }
  }
}

#doc 2
{
  "_index": "my-index-000001",
  "_type": "_doc",
  "_id": "0",
  "_source": {
    "doc":{
    	"field": []
    }
  }
}

#doc 3
{
  "_index": "my-index-000001",
  "_type": "_doc",
  "_id": "0",
  "_source": {
    "doc":{
    	"field": ["hello",""]
    }
  }
}

From the above documents is it possible to filter out only doc 1 and doc 2 as for these, the "field" either contains nothing in the array or only empty string(s).

Welcome to our community! :smiley:

What about something like;

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must_not": [
            {
              "exists": {
                "field": "your_field"
              }
            }
          ]
        }
      }
    }
  },
  "from": 0,
  "size": 500
}

Thanks for the reply... Happy to be on board!
I tried this but it throws the exception "no [query] registered for [filtered]"

Yeah I think there's an extra filtered in there that shouldn't be.

What about;

GET /_search
{
    "query": {
        "bool": {
            "must_not": {
                "exists": {
                    "field": "your_field"
                }
            }
        }
    }
}

Really appreciate your help but this query is returning all the documents, that contain array with empty strings or nonempty strings, can you please have a look at the sample docs in the questions? if there is anything I can add up there for reference?

If you are using keyword family field type, how about this?

GET /test_filter/_search
{
  "query":{
    "regexp": {
      "myField": ".+"
    }
  }
}

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