# Problem with painless script

**URL:** https://discuss.elastic.co/t/problem-with-painless-script/159298
**Category:** Elasticsearch
**Created:** [December 4, 2018, 6:49am UTC](https://discuss.elastic.co/t/problem-with-painless-script/159298 "2018-12-04T06:49:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Calvin\_Zhang](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@Calvin\_Zhang](https://discuss.elastic.co/u/Calvin_Zhang)
#### Post date: [December 4, 2018, 6:49am UTC](https://discuss.elastic.co/t/problem-with-painless-script/159298/1 "2018-12-04T06:49:41Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Calvin\_Zhang](https://avatars.discourse-cdn.com/v4/letter/c/e8c25b/32.png) [@Calvin\_Zhang](https://discuss.elastic.co/u/Calvin_Zhang)
#### Post date: [December 4, 2018, 7:16am UTC](https://discuss.elastic.co/t/problem-with-painless-script/159298/2 "2018-12-04T07:16:50Z")

</div>

Okay....problem solved....my mistake...  
"partParams in params" should be "partParams in params.entrySet()"  
script\_stack should be more accurate maybe.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 1, 2019, 7:28am UTC](https://discuss.elastic.co/t/problem-with-painless-script/159298/3 "2019-01-01T07:28:34Z")

</div>

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