Update_by_query updating in all the inner lists in a document?

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 ?

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