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

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

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