# Painless: dynamic variables in hash

**URL:** <https://discuss.elastic.co/t/painless-dynamic-variables-in-hash/182632>\
**Category:** Elasticsearch\
**Created:** [May 24, 2019, 11:29am UTC](https://discuss.elastic.co/t/painless-dynamic-variables-in-hash/182632 "2019-05-24T11:29:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![simple\_commentateur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simple_commentateur/32/45428_2.png) [@simple\_commentateur](https://discuss.elastic.co/u/simple_commentateur)\
**Post date:** [May 24, 2019, 11:29am UTC](https://discuss.elastic.co/t/painless-dynamic-variables-in-hash/182632/1 "2019-05-24T11:29:08Z")

</div>

hello,

i want to get a ctx.payload like this :

```
"transform": {
   "script": {
      "source": "ctx.payload.transform = []; def text = ['test1' : \"{{ctx.payload.hits.total}}\"]; ctx.payload.transform.add(text); return ctx.payload.transform;",
      "lang": "painless"
   }
},

```

But the value of {{ctx.payload.hits.total}} is not affected to 'test1' but it affect the string.

How can i pass the value ?

---

<div class="post-metadata">

**Author:** ![simple\_commentateur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simple_commentateur/32/45428_2.png) [@simple\_commentateur](https://discuss.elastic.co/u/simple_commentateur)\
**Post date:** [May 24, 2019, 11:58am UTC](https://discuss.elastic.co/t/painless-dynamic-variables-in-hash/182632/2 "2019-05-24T11:58:35Z")

</div>

I find the solution, i write it like that : ctx['payload']['hits']['total']

---

<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:** [June 21, 2019, 11:59am UTC](https://discuss.elastic.co/t/painless-dynamic-variables-in-hash/182632/3 "2019-06-21T11:59:37Z")

</div>

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