# A few Painless questions

**URL:** <https://discuss.elastic.co/t/a-few-painless-questions/115143>\
**Category:** Elasticsearch\
**Created:** [January 11, 2018, 4:55pm UTC](https://discuss.elastic.co/t/a-few-painless-questions/115143 "2018-01-11T16:55:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [January 11, 2018, 4:55pm UTC](https://discuss.elastic.co/t/a-few-painless-questions/115143/1 "2018-01-11T16:55:37Z")

</div>

I'm trying to get a better understanding of Painless and one thing that seems unclear to me is the `doc` field:

1. What is the difference between `doc['field_name']` and `doc['field_name'].value`?
2. Do I access nested fields like `doc['field_name']['nested_field']` or `doc['field_name.nested_field']`?
3. I'm kind of unclear on how to use the Painless API page to find methods and properties available for certain data types. For example, I know you can use `[3,4,5].length`, but can you use `length` on maps as well as arrays? I see in the docs I can use `add()` to add a value to an array, but can I do that with Maps too? What other functions are available? The API page seems hard for me to figure this out.

---

<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:** [January 11, 2018, 11:05pm UTC](https://discuss.elastic.co/t/a-few-painless-questions/115143/2 "2018-01-11T23:05:36Z")

</div>

1. `doc['field_name']` returns an accessor for the field, `.value` actually gets the value for the field
2. `doc['field\_name.nested\_field'] is the correct syntax. Note that I only used your terminology here, but nested _documents_ are not accessible (these are indexed as separate documents in lucene).
3. Painless is really just java with a couple groovy-like syntax features. So you should look at Java. The "array" you have there is actually an ArrayList, which is why you can call add on it. I don't know what to tell you other than if you can write java code, it should work, so look for java examples if in doubt.

---

<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:** [February 8, 2018, 11:05pm UTC](https://discuss.elastic.co/t/a-few-painless-questions/115143/3 "2018-02-08T23:05:48Z")

</div>

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