# Painless: How to simulate a hashmap as a variable for painless lab?

**URL:** <https://discuss.elastic.co/t/painless-how-to-simulate-a-hashmap-as-a-variable-for-painless-lab/291813>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [December 14, 2021, 2:24pm UTC](https://discuss.elastic.co/t/painless-how-to-simulate-a-hashmap-as-a-variable-for-painless-lab/291813 "2021-12-14T14:24:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kelk](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelk](https://discuss.elastic.co/u/kelk)\
**Post date:** [December 14, 2021, 2:24pm UTC](https://discuss.elastic.co/t/painless-how-to-simulate-a-hashmap-as-a-variable-for-painless-lab/291813/1 "2021-12-14T14:24:29Z")

</div>

Hi,  
I've got below painless snippet

```auto
// define sample data as hashmap (similar to Elastic output)
def buy_list = ' [{doc_count=13, category={buckets=[{doc_count=11, key=apple}, {doc_count=12, key=mango}, {doc_count=13, key=mango}, {doc_count=14, key=mango}]}, key=fruits} , {doc_count=34, category={buckets=[{doc_count=23, key=carrot}, {doc_count=41, key=beet}, {doc_count=21, key=potato}, {doc_count=21, key=pepper}]}, key=vegetables}]' ;

// Method to iterate and return lh_list
List lh_list = new ArrayList();
for (Map l1: buy_list) {
  for (Map l2: l1.category.buckets) {
    lh_list.add(l2.key);
  }
}
return lh_list

```

But the above code is not correct as the "definition" of the Hashmap is not working. All I want to put is sample data in format we get within watcher, so want to simulate in painless lab  
The above logic works in watcher when the data comes as `ctx.payload...` format

---

<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:** [January 11, 2022, 2:25pm UTC](https://discuss.elastic.co/t/painless-how-to-simulate-a-hashmap-as-a-variable-for-painless-lab/291813/2 "2022-01-11T14:25:11Z")

</div>

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