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

**URL:** <https://discuss.elastic.co/t/whats-the-difference-between-accessing-a-document-field-via-value-values-or-not-in-painless-script/203306>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [October 12, 2019, 6:32am UTC](https://discuss.elastic.co/t/whats-the-difference-between-accessing-a-document-field-via-value-values-or-not-in-painless-script/203306 "2019-10-12T06:32:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wusongchao](https://avatars.discourse-cdn.com/v4/letter/w/4af34b/32.png) [@wusongchao](https://discuss.elastic.co/u/wusongchao)\
**Post date:** [October 12, 2019, 6:32am UTC](https://discuss.elastic.co/t/whats-the-difference-between-accessing-a-document-field-via-value-values-or-not-in-painless-script/203306/1 "2019-10-12T06:32:11Z")

</div>

Suppose that i have a doc mapping field like below

```auto
{
    "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.

> <https://stackoverflow.com/questions/58351504/whats-the-difference-between-accessing-a-document-field-via-value-values-or-n>

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [October 12, 2019, 6:42pm UTC](https://discuss.elastic.co/t/whats-the-difference-between-accessing-a-document-field-via-value-values-or-not-in-painless-script/203306/2 "2019-10-12T18:42:12Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 9, 2019, 6:42pm UTC](https://discuss.elastic.co/t/whats-the-difference-between-accessing-a-document-field-via-value-values-or-not-in-painless-script/203306/3 "2019-11-09T18:42:16Z")

</div>

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