Hi there,
I am using Elasticsearch 6.2 and am trying to assign a nummeric value in a scripted update by query like so:
POST aarhuis/_update_by_query
{
"script" : {
"source" : "doc['SUMAB'] = doc['CNTA'] + doc['CNTB']",
"lang": "painless"
},
"query": {
"match_all": {}
}
}
All three fields are defined as being nummeric ( "CNTA": { "type": "integer" } and so on). But using the doc notation, with, or without .value extension, I keep getting errors, null_pointer_exception to be precise.
I have tried all sorts of combinations, and the npx is signalled at different places:
"doc['SUMBA'].value = doc['CNTA'].value + doc['CNTB'].value",
" ^---- HERE"
"doc['SUMBA'] = doc['CNTA'] + doc['CNTB']",
" ^---- HERE"
If I try checking for null, I'll get npx in the null check:
if(doc['CNTA'] != null && doc['CNTB'] != null) {doc['SUMAB'] = doc['CNTA'] + doc['CNTB'];}
"if(doc['CNTA'] != null && doc['CNTB'] != null) {",
" ^---- HERE"
But the best is yet to come!
First, when i use the expression
doc['CNTA'].value + doc['CNTB'].value
in a scripted field, it just works as expected!
But worst, when I change for
ctx._source.SUMAB = ctx._source.CNTA + ctx._source.CNTB
in the update query, the query will pass without failure, but it will treat both fields as text and concatenate them instead of calculating, giving me 33 for 3 + 3 and not 6.
I feel I'm making some stupid mistake somewhere (or the documentation is missing some elementary hint), so I do not file this as a bug report for now. But having spend more than a full day on this I am pretty close to madness. "Help! I need somebody..."