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

Following is my document structure

"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

ctx._source.docFieldPath.putAll(content)

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

But the following works:

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.