# Hou can i update nested Object

**URL:** <https://discuss.elastic.co/t/hou-can-i-update-nested-object/24894>\
**Category:** Elasticsearch\
**Created:** [July 4, 2015, 12:01pm UTC](https://discuss.elastic.co/t/hou-can-i-update-nested-object/24894 "2015-07-04T12:01:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Verma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandeep_verma/32/12517_2.png) [@Sandeep\_Verma](https://discuss.elastic.co/u/Sandeep_Verma)\
**Post date:** [July 4, 2015, 12:01pm UTC](https://discuss.elastic.co/t/hou-can-i-update-nested-object/24894/1 "2015-07-04T12:01:15Z")

</div>

I wanted to update nested. How can i increment and update value of neseted Obj. I m using Bulk update And My query is For brand is Below But it takes Lots Of time.Is There any way

```
{"update":{"_id":"5597c7741d4213241f9925be","type":"user","index":"jal","routing":17,"_retry_on_conflict":5,"refresh":true}}
{"lang":"mvel","script":"foreach (item : ctx._source.brand) { if (item['key'] == key) { if(item['name']==null){item['name'] =name;} } }","params":{"key":"4157_purchased","name":4157}}
{"update":{"_id":"5597c7741d4213241f9925be","type":"user","index":"jal","routing":17,"_retry_on_conflict":5,"refresh":true}}
{"lang":"mvel","script":"foreach (item : ctx._source.brand) { if (item['key'] == key) { if(item['action']==null){item['action'] =action;} } }","params":{"key":"4157_purchased","action":"purchased"}}

    {"update":{"_id":"5597c7741d4213241f9925be","type":"user","index":"jal","routing":17,"_retry_on_conflict":5,"refresh":true}}
    {"lang":"mvel","script":"foreach (item : ctx._source.brand) { if (item['key'] == key) {if(item['price']==null){item['price']=price;}else{ item['price']=item['price']+ price;} } }","params":{"key":"4157_purchased","price":0}}
    {"update":{"_id":"5597c7741d4213241f9925be","type":"user","index":"jal","routing":17,"_retry_on_conflict":5,"refresh":true}}
    {"lang":"mvel","script":"foreach (item : ctx._source.brand) { if (item['key'] == key) {if(item['count']==null){item['count']=count;}else{ item['count']=item['count']+ count;} } }","params":{"key":"4157_purchased","count":1}}
    {"update":{"_id":"5597c7741d4213241f9925be","type":"user","index":"jal","routing":17,"_retry_on_conflict":5,"refresh":true}}
    {"lang":"mvel","script":"foreach (item : ctx._source.brand) { if (item['key'] == key) {if(item['last_date']==null){item['last_date']=last_date;}else{ item['last_date'] = last_date; } }}","params":{"key":"4157_purchased","last_date":"2015-06-18T02:01:30"}}
    {"update":{"_id":"5597c7741d4213241f9925be","type":"user","index":"jal","routing":17,"_retry_on_conflict":5,"refresh":true}}
    {"lang":"mvel","script":"foreach (item : ctx._source.brand) { if (item['key'] == key) {if(item['without_promo']==null){item['without_promo']=without_promo;}else{ item['without_promo']=item['without_promo']+ without_promo;} } }","params":{"key":"4157_purchased","without_promo":1}}

```

My nested Object Looking Like this

```
{
               "_userId": "hr324hdie93hdjdo391",
               "_shardId": 2,
               "brand": [
                  {
                     "price": 140,
                     "name": 23,
                     "count": 7,
                     "without_promo": 7,
                     "action": "purchased",
                     "key": "23_purchased",
                     "last_date": "2015-07-04T10:10:25"
                  }
               ],
               "product": [
                  {
                     "price": 140,
                     "with_promo": 7,
                     "name": 28,
                     "count": 7,
                     "action": "purchased",
                     "key": "28_purchased",
                     "last_date": "2015-07-04T10:10:25"
                  },
                  {
                     "price": 40,
                     "with_promo": 2,
                     "name": 29,
                     "count": 2,
                     "action": "purchased",
                     "key": "29_purchased",
                     "last_date": "2015-07-04T06:25:30"
                  }
                 
               ],
               "category": [
                  {
                     "price": 140,
                     "with_promo": 7,
                     "name": 123,
                     "count": 7,
                     "action": "purchased",
                     "key": "123_purchased",
                     "last_date": "2015-07-04T10:10:25"
                  },
                  {
                     "price": 40,
                     "with_promo": 2,
                     "name": 124,
                     "count": 2,
                     "action": "purchased",
                     "key": "124_purchased",
                     "last_date": "2015-07-04T06:25:30"
                  } ]
            }
```

---

<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:** [July 6, 2015, 8:11am UTC](https://discuss.elastic.co/t/hou-can-i-update-nested-object/24894/2 "2015-07-06T08:11:03Z")

</div>

Please keep it to one thread 😄

> [@Bulk update taking time on updating nested properties](https://discuss.elastic.co/t/bulk-update-taking-time-on-updating-nested-properties/24810/):
>
> I am running bulk query on elastic search for updating user's nested properties. Below is the query which I am executing to update user's properties. It updates around 200 properties of single user. It takes around 5000 mili seconds Machine configuration on Amazon Aws Master : 1, c4.large Data Nodes : 2 c4.2xlarge POST /INDEX\_NAME/user/\_bulk {"update":{"\_id":"55950ed51d4213241f7c38b4","type":"user","index":"jal","routing":2,"\_retry\_on\_conflict":5,"refresh":true}} {"lang":"mvel","script":…

---

<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:** [July 6, 2015, 8:11am UTC](https://discuss.elastic.co/t/hou-can-i-update-nested-object/24894/3 "2015-07-06T08:11:07Z")

</div>


