# How to update fields in nested document without script

**URL:** https://discuss.elastic.co/t/how-to-update-fields-in-nested-document-without-script/302999
**Category:** Elasticsearch
**Tags:** painless
**Created:** [April 22, 2022, 9:00am UTC](https://discuss.elastic.co/t/how-to-update-fields-in-nested-document-without-script/302999 "2022-04-22T09:00:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![martin\_wun](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@martin\_wun](https://discuss.elastic.co/u/martin_wun)
#### Post date: [April 22, 2022, 9:00am UTC](https://discuss.elastic.co/t/how-to-update-fields-in-nested-document-without-script/302999/1 "2022-04-22T09:00:18Z")

</div>

Hi all,

Is there a way to update an individual field in a nested document without having to use a script? I have found some answers here, but they all use a painless script in some form. E.g.:

> [@How to update field inside nested document?](https://discuss.elastic.co/t/how-to-update-field-inside-nested-document/119202/2):
>
> Have a look at scripted updates in the [Update API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_scripted_updates). POST tmp\_test/doc/1/\_update { "script": { "lang": "painless", "source": "ctx.\_source.LineItem[0].CONumber = params.CONumber", "params": { "CONumber": "9876" } } }

> [@Updating nested field with update\_by\_query API](https://discuss.elastic.co/t/updating-nested-field-with-update-by-query-api/53910):
>
> Hello, I'm trying to update a nested field of my document through the update\_by\_query API, but I"m getting a casting error: [class\_cast\_exception] java.lang.String cannot be cast to java.util.Map This is the body of my request; { "query":{ "term":{ "acl\_policy.group\_id":"11550" } }, "script":"ctx.\_source.acl\_policy = newAclPolicy", "params":{ "newAclPolicy":{ "group\_id":"11550", "canned\_group":"company", …

For example, say I have documents that represent user groups. Each group doc has nested docs with all the users of the group. How can I update the name field on one of these users, assuming that I have another field that serves as the unique ID?  
Thanks!

Cheers,  
Martin

---

<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: [May 20, 2022, 9:00am UTC](https://discuss.elastic.co/t/how-to-update-fields-in-nested-document-without-script/302999/2 "2022-05-20T09:00:47Z")

</div>

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