# Update only a single field of a subobject?

**URL:** https://discuss.elastic.co/t/update-only-a-single-field-of-a-subobject/39815
**Category:** Elasticsearch
**Created:** [January 21, 2016, 8:32pm UTC](https://discuss.elastic.co/t/update-only-a-single-field-of-a-subobject/39815 "2016-01-21T20:32:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jpblair](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jpblair](https://discuss.elastic.co/u/jpblair)
#### Post date: [January 21, 2016, 8:32pm UTC](https://discuss.elastic.co/t/update-only-a-single-field-of-a-subobject/39815/1 "2016-01-21T20:32:14Z")

</div>

So I noticed [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_updates_with_a_partial_document) that you can use the `doc` field in the update API to update single fields. However, I can't seem to get this working when the field is not at the root of the document, without erasing the other fields in the subobject. For example, if I have a document with this structure:

```
{
    "parent": {
        "child1":1,
        "child2":2,
        "child3":3,
        "child4":4
    }
}

```

How can I update ONLY `child2`? If I send `{"parent":{"child2":5}}`, that will replace the whole `parent` object. I had thought that maybe I could do `{"parent.child2":5}`, but that appears to create a new field with the literal name `parent.child2`. Is what I'm trying to do possible? I know I can retrieve the current value of `parent`, modify it client-side and resend, but wouldn't there be potential race conditions from that? Thanks.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [January 22, 2016, 6:25am UTC](https://discuss.elastic.co/t/update-only-a-single-field-of-a-subobject/39815/2 "2016-01-22T06:25:30Z")

</div>

You need to update the entire structure.

Nested documents may work here, but I am no expert there.

---

<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: [July 5, 2017, 11:22pm UTC](https://discuss.elastic.co/t/update-only-a-single-field-of-a-subobject/39815/3 "2017-07-05T23:22:20Z")

</div>


