I'm trying to run the _update_by_query to create a new field that takes a value of an existing field and adds say 1 for example.
POST newlogstash/_update_by_query
{
"script": {
"lang": "painless",
"inline": "if (ctx._source.alert.severity > 2) {ctx._source.cmertic += 1;}"
}
}
but I get the following error, and my hunch is that because the field alert.severity is not always present. So how do I check if a field exist within the inline syntax
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if (ctx._source.alert.severity > 2) {",
" ^---- HERE"
],
"script": "if (ctx._source.alert.severity > 2) {ctx._source.cmertic += 1;}",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if (ctx._source.alert.severity > 2) {",
" ^---- HERE"
],
"script": "if (ctx._source.alert.severity > 2) {ctx._source.cmertic += 1;}",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
},
"status": 500
}