# How to add/Update a nested object having more than 2 level

**URL:** <https://discuss.elastic.co/t/how-to-add-update-a-nested-object-having-more-than-2-level/69681>\
**Category:** Elasticsearch\
**Created:** [December 21, 2016, 3:36pm UTC](https://discuss.elastic.co/t/how-to-add-update-a-nested-object-having-more-than-2-level/69681 "2016-12-21T15:36:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sagesh](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sagesh](https://discuss.elastic.co/u/Sagesh)\
**Post date:** [December 21, 2016, 3:36pm UTC](https://discuss.elastic.co/t/how-to-add-update-a-nested-object-having-more-than-2-level/69681/1 "2016-12-21T15:36:15Z")

</div>

Using elastic search 5.x

Have an JSON object like

"Employees"  
{  
"Employee":  
{  
"Id" : "Emp002"  
"name" : "Martin",  
"Qualification" :[{  
"Course" : "MTech",  
"Year" : "2016"  
}],  
"Manager": [  
{  
"Id" : "Emp001"  
"name" : "Joseph",  
"Qualification" :[{  
"Course" : "BTech",  
"Year" : "2010"  
}]  
}  
},  
"Employee":  
{  
"Id" : "Emp004"  
"name" : "Kumar",  
"Qualification" :[{  
"Course" : "MCA",  
"Year" : "2014"  
}],  
"Manager": [  
{  
"Id" : "Emp003"  
"name" : "George",  
"Qualification" :[{  
"Course" : "MTech",  
"Year" : "2008"  
}]  
}  
}  
}

Wanted to add a new Qualification to "Manager" for the "Id" : "Emp004"

"Qualification" :[{  
"Course" : "BTech",  
"Year" : "2005"  
}]

## **Mapping**

PUT /employees  
{  
"mappings": {  
"employees" :{  
"properties": {  
"employee" : {  
"type": "nested",  
"properties" :{  
"Id" : {"type":"string" },  
"name" : {"type":"string" },  
"Qualification" : {"type":"nested",  
"properties" :{  
"Course" : {"type":"string" },  
"Year" : {"type":"string" }  
}  
},  
"manager" : {  
"type": "nested",  
"properties" :{  
"Id" : {"type":"string" },  
"name" : {"type":"string" },  
"Qualification" : {"type":"nested",  
"properties" :{  
"Course" : {"type":"string" },  
"Year" : {"type":"string" }  
}  
}  
}

```
                }
                    }
                    }
                }
            }
        }
}

```

## **Query**

POST /employees/employees/Emp002/\_update  
{  
"script":{  
"lang": "painless",  
"inline": "ctx.\_source.employee.manager.Qualification.add(params.New\_Qualification) ",  
"params": {  
"New\_Qualification": {  
"Qualification" :[{  
"Course" : "BTech",  
"Year" : "2000"  
}]  
}  
}  
}  
}

## **Error**

{  
"error": {  
"root\_cause": [  
{  
"type": "remote\_transport\_exception",  
"reason": "[ubuntu][127.0.0.1:9300][indices:data/write/update[s]]"  
}  
],  
"type": "illegal\_argument\_exception",  
"reason": "failed to execute script",  
"caused\_by": {  
"type": "script\_exception",  
"reason": "runtime error",  
"caused\_by": {  
"type": "illegal\_argument\_exception",  
"reason": "Illegal list shortcut value [manager]."  
},  
"script\_stack": [  
"ctx.\_source.employee.manager.Qualification.add(params.New\_Qualification) ",  
" ^---- HERE"  
],  
"script": "ctx.\_source.employee.manager.Qualification.add(params.New\_Qualification) ",  
"lang": "painless"  
}  
},  
"status": 400  
}

If any one can give directions to achieve this will be appreciated.

Thanks,  
Sagesh

---

<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:** [January 18, 2017, 3:36pm UTC](https://discuss.elastic.co/t/how-to-add-update-a-nested-object-having-more-than-2-level/69681/2 "2017-01-18T15:36:19Z")

</div>

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