Problem with painless script

(Calvin Zhang) #1

I was executing a bulk upsert with script when an error occurred.
Here is the error message:
"error": {
"type": "illegal_argument_exception",
"reason": "failed to execute script",
"caused_by": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"valueMap = new HashMap();",
" ^---- HERE"
"script": "boolean expire(def partParams, def currentSource) {String versionKey = 'data_version.' + partParams.getKey();if (currentSource.get(versionKey) == null) {return false;}long currentVersion = Long.parseLong(currentSource.get(versionKey).toString());long newVersion = Long.parseLong(partParams.get('data_version').toString());if (newVersion > currentVersion) {return false;}return true;}void process(def ctx, def params) {Map valueMap = new HashMap();for (partParams in params) {if (partParams.getKey().equals('ctx')) {continue;}if (ctx.op=='create' || !expire(partParams, ctx._source)) {valueMap.putAll(partParams.get('source'));valueMap.put('data_version.' + partParams.getKey(), partParams.get('data_version'));}}if (valueMap.size() == 0) {ctx.op = 'noop';} else {for (value in valueMap.entrySet()) {ctx._source.put(value.getKey(), value.getValue());}}}process(ctx, params);",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Cannot iterate over [java.util.HashMap]"
What does the error mean? What's wrong with the script?

(Calvin Zhang) #2

Okay....problem mistake...
"partParams in params" should be "partParams in params.entrySet()"
script_stack should be more accurate maybe.

(system) closed #3

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