0

According to Official 7.x document Link

While a field is deemed non-existent if the JSON value is null or [], these values will indicate the field does exist:

Empty strings, such as "" or "-" Arrays containing null and another value, such as [null, "foo"] A custom null-value, defined in field mapping

However, My es not consider "" as not existed. Here is my Data:

"_source" : {
      "chat_msg" : {
        "action" : "send",
        "from" : "t",
        "msgid" : "6505946507184390735_161_external",
        "msgtime" : 1623396135015,
        "msgtype" : "text",
        "roomid" : "",

Now, When I do Query As :

GET enterprise_chat_data/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "chat_msg.roomid"
          }
        }
      ]
    }
  }
}

Result:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

It Hit Nothing. Am I Wrong About Something?

1 Answer 1

1

I think you have misunderstood the documentation. In the documentation, it is written that if a field have value as empty strings, such as "" or "-", then that field will be considered to be existing.

Due to this when you are querying for must_not exists query for "chat_msg.roomid" field, you are getting empty results, as in the data you have indexed the value of "chat_msg.roomid" field as ""

Update 1:

You can use term query to search for documents having field value of chat_msg.roomid as ""

{
  "query": {
    "term": {
      "chat_msg.roomid.keyword": ""
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

omy.... eye... My I Ask How to find all roomId which is ""?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.