# In a painless script how do I iterate through document keys based on a pattern?

**URL:** <https://discuss.elastic.co/t/in-a-painless-script-how-do-i-iterate-through-document-keys-based-on-a-pattern/238552>\
**Category:** Kibana\
**Created:** [June 24, 2020, 7:32pm UTC](https://discuss.elastic.co/t/in-a-painless-script-how-do-i-iterate-through-document-keys-based-on-a-pattern/238552 "2020-06-24T19:32:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mattkime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkime/32/43522_2.png) [@mattkime](https://discuss.elastic.co/u/mattkime)\
**Post date:** [June 24, 2020, 7:43pm UTC](https://discuss.elastic.co/t/in-a-painless-script-how-do-i-iterate-through-document-keys-based-on-a-pattern/238552/2 "2020-06-24T19:43:54Z")

</div>

@gthang

Have you tried iterating over the `doc` map? [https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-field-context.html](https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-field-context.html)

Someone working through a similar problem - [Loop over a map in Painless](https://discuss.elastic.co/t/loop-over-a-map-in-painless/70308)

---

_[View the full topic](https://discuss.elastic.co/t/in-a-painless-script-how-do-i-iterate-through-document-keys-based-on-a-pattern/238552)._
