# Update\_by\_query updating in all the inner lists in a document?

**URL:** <https://discuss.elastic.co/t/update-by-query-updating-in-all-the-inner-lists-in-a-document/89492>\
**Category:** Elasticsearch\
**Created:** [June 15, 2017, 3:21am UTC](https://discuss.elastic.co/t/update-by-query-updating-in-all-the-inner-lists-in-a-document/89492 "2017-06-15T03:21:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [June 15, 2017, 3:21am UTC](https://discuss.elastic.co/t/update-by-query-updating-in-all-the-inner-lists-in-a-document/89492/1 "2017-06-15T03:21:48Z")

</div>

Hi,

My usecase is like this:

I have some documents which have lists in them the mappings are like this ;

```
"University": {
            "type": "nested",
            "include_in_parent": true,
            "properties": {
              "State": {
                "type": "string",
                "index": "not_analyzed"
              },
              "Code": {
                "type": "long"
              },
              "Pin": {
                "type": "long"
              },
         }
 }

```

The list in the document is like this:

```
"University": [
            {
              "State": "USA",
              "Code": 131299,
              "Pin": 236
            },
          {
            "State": "UK",
              "Code": 135829,
              "Pin": 145
          },
          {
           "State": "HMD",
              "Code": 12399,
              "Pin": 200
          }
]

```

I want to change `State` and also i need to add a new field in all the documents in the index based on `Code & Pin`.

I used this update\_by\_query to add a new field to the documents that have `Code & Pin`

```
POST data/details/_update_by_query?conflicts=proceed
{
    "query": {
        "bool": {
            "must": [
               {
                  "term" : { "Code" : 12399 } 
               },
               {
                   "term": { "Pin": 200 }        
                   }
         ]
        }
        },
    "script": { 
    "inline" : "for(i in ctx._source.University) { i.Name = status}",
   "params": {
     "status": "UCLA"
   }
    }
    
}

```

The problem is it is updating in all updating in all the inner lists in a list rather than updating in particular matched one. The output is like this :

```
"University": [
                {
                  "State": "USA",
                  "Code": 131299,
                  "Pin": 236,
                  "Name": "UCLA"
                },
              {
                "State": "UK",
                  "Code": 135829,
                  "Pin": 145,
                  "Name": "UCLA"
              },
              {
               "State": "HMD",
                  "Code": 12399,
                  "Pin": 200,
                 "Name": "UCLA"
              }
    ]

```

How can avoid this because ?

---

<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 13, 2017, 3:22am UTC](https://discuss.elastic.co/t/update-by-query-updating-in-all-the-inner-lists-in-a-document/89492/2 "2017-07-13T03:22:03Z")

</div>

Closed on July 13, 2017, 3:22am UTC

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