I have a simple Elasticsearch query with a custom sort painless script that affects the order of the returned results. However, I noticed that the script doesn’t work as expected for all of the document fields, namely the maps and the nested fields. In order to debug the issue I made a small change to the script (see the image below).
As it can be seen from the image, the document in the results has a sort score 10 even though it contains the my_data
object. Why would this happen? Is there any other way to check the existence of such fields and properly iterate over its keys?
I even tried avoiding the check for the existence of the key in the document as I know that all of the documents in the index contain the my_data
field, but when I do so I get the following error: No field found for [my_data] in mapping
. The field is properly defined in the index mapping.