Hi I'm trying to set an object field from another using an update query but am getting an error.
Currently by doc has an event object in the root of the doc with a field: id
i.e.
{
event { id: 1 }
}
all the documents have a duration_secs field:
i.e.
{
event { id: 1 },
duration_secs: 10
}
But to make existing documents more ECS compliant I want to add the duration to the event object as duration..
i.e.
{
event { id: 1, duration: 10 },
duration_secs: 10
}
I have used an _update_by_query before, but am getting an error.
Here is my request:
POST myindex-*/_update_by_query
{
"query": {
"bool": {
"should": [
{
"exists": {
"field" : "duration_secs"
}
},
{
"exists": {
"field": "event"
}
}
]
}
},
"script" : {
"inline": "ctx._source.event.duration = ctx._source.duration_secs; ",
"lang": "painless"
}
}
And the error is:
{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"ctx._source.event.duration = ctx._source.duration_secs; ",
" ^---- HERE"
],
"script" : "ctx._source.event.duration = ctx._source.duration_secs; ",
"lang" : "painless",
"position" : {
"offset" : 17,
"start" : 0,
"end" : 56
}
}
],
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"ctx._source.event.duration = ctx._source.duration_secs; ",
" ^---- HERE"
],
"script" : "ctx._source.event.duration = ctx._source.duration_secs; ",
"lang" : "painless",
"position" : {
"offset" : 17,
"start" : 0,
"end" : 56
},
"caused_by" : {
"type" : "null_pointer_exception",
"reason" : "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null"
}
},
"status" : 400
}
I cant find any resources on the error:
Cannot invoke "Object.getClass()" because "callArgs[0]" is null
But suspect it is a scoping issue of some sort?