The update gets committed when I use this query.
POST my_collegues_names/_update_by_query?error_trace=true
{
"script": {
"lang": "painless",
"source": "ctx._source.age +=params.last",
"params": {
"last": 5
}
},
"query": {
"match": {
"_id": 21
}
}
}
but I get error when I try to run this query.
POST my_collegues_names/_update_by_query?error_trace=true
{
"script_fields":{
"scriptname":{
"script": {
"lang": "painless",
"source": "doc['age']+=params.last",
"params": {
"last": 20
}
}
}
},
"query": {
"match": {
"_id": 21
}
}
}
Error_trace
ScriptException[runtime error]; nested: NullPointerException;\r\n\tat org.elasticsearch.painless.PainlessScript.convertToScriptException(PainlessScript.java:94)\r\n\tat org.elasticsearch.painless.PainlessScript$Script.execute(doc['age']= doc['age'] +params.last:4)\r\n\tat org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:105)\r\n\tat org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction$ScriptApplier.apply(AbstractAsyncBulkByScrollAction.java:819)\r\n\tat org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction$ScriptApplier.apply(AbstractAsyncBulkByScrollAction.java:768)\r\n\tat org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction.buildBulk(AbstractAsyncBulkByScrollAction.java:216)\r\n\tat org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction.prepareBulkRequest(AbstractAsyncBulkByScrollAction.java:326)\r\n\tat org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction$1.doRun(AbstractAsyncBulkByScrollAction.java:289)\r\n\tat org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:723)\r\n\tat org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)\r\n\tat org.elasticsearch.index.reindex.WorkerBulkByScrollTaskState$RunOnce.doRun(WorkerBulkByScrollTaskState.java:321)\r\n\tat org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)\r\n\tat org.elasticsearch.index.reindex.WorkerBulkByScrollTaskState$DelayedPrepareBulkRequest$1.doRun(WorkerBulkByScrollTaskState.java:257)\r\n\tat org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:723)\r\n\tat org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\r\n\tat java.lang.Thread.run(Thread.java:748)\r\nCaused by: java.lang.NullPointerException\r\n\tat org.elasticsearch.painless.PainlessScript$Script.execute(doc['age']= doc['age'] +params.last:17)\r\n\t... 16 more\r\n"
I am not able to understand why can't I use doc['age'] in my script.
Please help