Hou can i update nested Object


(Sandeep Verma) #1

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"
                  }               ]
            }

(Mark Walkom) #2

Please keep it to one thread :smile:


(Mark Walkom) #3