# Looping through inner object arrays in painless

**URL:** <https://discuss.elastic.co/t/looping-through-inner-object-arrays-in-painless/90342>\
**Category:** Elasticsearch\
**Created:** [June 21, 2017, 6:00pm UTC](https://discuss.elastic.co/t/looping-through-inner-object-arrays-in-painless/90342 "2017-06-21T18:00:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mett](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@mett](https://discuss.elastic.co/u/mett)\
**Post date:** [June 21, 2017, 6:00pm UTC](https://discuss.elastic.co/t/looping-through-inner-object-arrays-in-painless/90342/1 "2017-06-21T18:00:22Z")

</div>

`for( int i = 0; i < doc['keywords'].size(); i ++ )`

My painless for loop above is attempting to execute in a scripted\_metric aggregation in the map\_script scope. I have a bunch of keyword entries that each have a 'key' (holds a word) and 'value' (holds an integer representing the number of occurrences of that word in another field elsewhere in the doc).

But when executing it I get an IllegalArgumentException with reason 'No field found for [keywords] in mapping with types []'

Is it possible to loop through arrays in json docs indexed in elastic via painless?

---

<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:** [July 19, 2017, 6:00pm UTC](https://discuss.elastic.co/t/looping-through-inner-object-arrays-in-painless/90342/2 "2017-07-19T18:00:29Z")

</div>

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