# Update specific nested object

**URL:** https://discuss.elastic.co/t/update-specific-nested-object/206168
**Category:** Elasticsearch
**Created:** [November 1, 2019, 1:05pm UTC](https://discuss.elastic.co/t/update-specific-nested-object/206168 "2019-11-01T13:05:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Vlad\_Dogarescu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vlad_dogarescu/32/56949_2.png) [@Vlad\_Dogarescu](https://discuss.elastic.co/u/Vlad_Dogarescu)
#### Post date: [November 1, 2019, 1:05pm UTC](https://discuss.elastic.co/t/update-specific-nested-object/206168/1 "2019-11-01T13:05:47Z")

</div>

I have hotel documents that each have rooms of nested type.

```
{
id: hotel_id,
   rooms: [
     {
        id: room_id_1,
        name: "room 1 name"
      },
      {
        id: room_id_2,
        name: "room 2 name"
      },
      ....
  ]
}

```

And I want to update only single field from a specific room. I am trying with the Update api, update the room with id 2 from the hotel document with id 1:

```
POST hotels/_update/1
{
  "script" : {
    "source" : "if(ctx._source.rooms.id == 2) { ctx._source.rooms.name = params.new_name }",
    "lang" : "painless",
    "params" : {
        "new_name" : "new room name"
    }  
  } 
}

```

I get this error "Illegal list shortcut value [id]" from ES.

Thanks!

---

<div class="post-metadata">

### Author: ![Vlad\_Dogarescu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vlad_dogarescu/32/56949_2.png) [@Vlad\_Dogarescu](https://discuss.elastic.co/u/Vlad_Dogarescu)
#### Post date: [November 1, 2019, 3:54pm UTC](https://discuss.elastic.co/t/update-specific-nested-object/206168/2 "2019-11-01T15:54:52Z")

</div>

it was so obvious.. I had to loop through the rooms..

> <https://stackoverflow.com/questions/58659527/elastic-search-update-specific-nested-object>

---

<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: [November 29, 2019, 3:54pm UTC](https://discuss.elastic.co/t/update-specific-nested-object/206168/3 "2019-11-29T15:54:53Z")

</div>

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