Search empty string not working

hi there,

I am searching ES to find empty string field using "must_not" and exists as follows, but it returns "0" hits. After I change the query to "must" and exists I am getting all hits where the filed having empty value as follows. Any help!

{
  "query": {
    "bool": {
      
      "must": [
        {
          "exists": {
            "field": "audoc.author_name.preferred_name.preferred_first"
          }
        }
      ]
    }
    
  }
}

result looks as follows:

"preferred_name" : {
                "preferred_first" : "",
                "preferred_ini" : "",
                "preferred_last" : ""
              }

Hey,

so the exists query matches, if the field itself exists in the JSON document which is true in your result, as the field is clearly there.

You seem to search for data existing in this field - which is much harder, when data is being indexed. I'd try a different approach, and either remove that field at index time, when there is no data in, so that the exists query works,or add a another field (a boolean) like is_preferred_first_empty, that is true or false and also added on indexing.

if you do not want to change your ingestions mechanism, you can always use the ingest node functionality and a script processor to do this.