What's the difference between accessing a document field via .value/.values or not in painless script?

Suppose that i have a doc mapping field like below

{
    "template": {
        "mappings":{
            "template":{
                "properties": {
                    "sth": {
                        "type": "long"
                    }
                }
            }
        }
    }
}

The field sth is the type of array.

I want to check whether the field sth contains a value or not, so i write painless script like doc['sth'].values.contains((long)1)

It works. However, if i write doc['sth'].contains((long)1) , accessing the field not via .values , it also can works.

I've also tried some instance method like isEmpty() , size() , both can work whether via .values or not.

So, what's the difference between accessing a document field via .value/.values or not in painless script? What does painless do under the hood?

Here's the relation topic on stackoverflow.

Historically .values was the way to access multiple values. However, the return type of doc was changed to be a List of values, so .values was redundant, as you found. For this reason, we removed .values in recent versions (maybe 7.0, I don't remember for sure).

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