Handling of null and [] (empty list)

Hi everybody, I am very new to Elasticsearch and I have a question regarding the handling of null and [] (empty list) values. Specifically, in my dummy index example, I have a document as follows

{
        "hits": [
            {
                "_index": "dummy",
                "_type": "_doc",
                "_id": "4c9bc4adbd5f572d708428f3df4dbf55",
                "_score": 17.805637,
                "_source": {
                    "id": 81863,
                    "created_at": "2022-06-14 10:23:31",
                    "updated_at": "2022-06-14 10:23:31",
                    "meta_data": "",
                    "acl": {
                        "species": null,
                        "roles": null,   <--- null value
                        "tools": null
                    },
                    "category": ""
                }
            }
        ]
    }
}

Here, it is noticeable that the field acl.roles is null. Additionally, in the same index, there is another document which looks like this

{
        "hits": [
            {
                "_index": "dummy",
                "_type": "_doc",
                "_id": "10a0a66bf7b60ed28e1ced36bd59934a",
                "_score": 15.609104,
                "_source": {
                    "id": 65690,
                    "created_at": "2020-10-02 09:46:00",
                    "updated_at": "2020-10-02 09:46:00",
                    "meta_data": "a:0:{}",
                    "acl": {
                        "species": [],
                        "roles": [],    <--- empty list
                        "tools": []
                    },
                    "category": "PERSONAL"
                }
            }
        ]
    }
}

So in the dummy index, the field acl.roles can have either a null value or an [] (empty list) value. Could you guys please explain to me:

  • What is the difference between null and [] in Elasticsearch?
  • Is it possible to count the number of documents that have acl.roles=null and acl.roles=[]? If so, what is the difference between the two queries? I try to do a query like below but I don't really understand how Elasticsearch handle these stuff ??
GET dummy/_count
{
  "query": {
    "bool": {
      "must_not": {
        "exists": {
          "field": "acl.roles"
        }
      }
    }
  }
}

If I misunderstand something, please, point it out for me, I really appreciate that.

Thank you guys !!!

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