# How to use a variable with ctx\['\_source'\] without tokenising it

**URL:** <https://discuss.elastic.co/t/how-to-use-a-variable-with-ctx-source-without-tokenising-it/225164>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [March 26, 2020, 10:26am UTC](https://discuss.elastic.co/t/how-to-use-a-variable-with-ctx-source-without-tokenising-it/225164 "2020-03-26T10:26:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![uddhav](https://avatars.discourse-cdn.com/v4/letter/u/67e7ee/32.png) [@uddhav](https://discuss.elastic.co/u/uddhav)\
**Post date:** [March 26, 2020, 10:26am UTC](https://discuss.elastic.co/t/how-to-use-a-variable-with-ctx-source-without-tokenising-it/225164/1 "2020-03-26T10:26:28Z")

</div>

Following is my document structure

```auto
"ListOfResourcesForTheTeam”:[{"Resource":{"Name": "XYZ", "Phone": 31213}}, { "Resource":{"Name": "ABC", "Phone": 4365}}]

```

Using update\_by\_query using painless scripting I am trying to update the phone number of the second resource as following:

docFieldPath = ListOfResourcesForTheTeam.1.Resource

```auto
ctx._source.docFieldPath.putAll(content)

```

The script errors out as it tries to find “docFieldPath”.

But the following works:

```auto
ctx['_source'][firstPartOfDocFieldPath][secondPartOfDocFieldPathAsInteger][thirdPartOfDocFieldPath].putAll(content);

```

Is there a way in painless script such that I can directly use docFieldPath instead of tokenising it.

---

<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:** [April 23, 2020, 10:26am UTC](https://discuss.elastic.co/t/how-to-use-a-variable-with-ctx-source-without-tokenising-it/225164/2 "2020-04-23T10:26:32Z")

</div>

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