Hello,
I am using a scripted metric, which is :
"scripted_metric": {
"init_script": "state.nodes = new HashMap();",
"map_script": "int jtime = 1538438400 ; for (int i = jtime; i < jtime+2; ++i) {if (doc.time_start.value < i && doc.time_end.value > i) {state.nodes[i] = doc.nodelist_expand}}",
"combine_script": "def result = new HashMap(); for (entry in state.nodes.entrySet()) { if (result.containsKey(entry.getKey())) { for (n in entry.getValue()) { result[entry.getKey()].add(n); } } else { result[entry.getKey().toString()]=entry.getValue(); }} return result;",
"reduce_script": "def result = new HashMap(); for (s in states) { for (entry in s.entrySet()) { if (result.containsKey(entry.getKey())) { for (n in entry.getValue()) { result[entry.getKey()].add(n); } } else { result[entry.getKey().toString()]=entry.getValue(); } } } return result;" }
And i get this error :
{
"error": {
"root_cause": [],
"type": "search_phase_execution_exception",
"reason": "",
"phase": "fetch",
"grouped": true,
"failed_shards": [],
"caused_by": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.index.fielddata.ScriptDocValues.add(ScriptDocValues.java:97)",
"java.util.AbstractList.add(AbstractList.java:108)",
"result[entry.getKey()].add(n); } } else { ",
" ^---- HERE"
],
"script": "def result = new HashMap(); for (s in states) { for (entry in s.entrySet()) { if (result.containsKey(entry.getKey())) { for (n in entry.getValue()) { result[entry.getKey()].add(n); } } else { result[entry.getKey().toString()]=entry.getValue(); } } } return result;",
"lang": "painless",
"caused_by": {
"type": "unsupported_operation_exception",
"reason": "doc values are unmodifiable"
}
}
},
"status": 503
}
I dont understand it, i dont try to modify a doc values, just a hashmap which is define in the reduce_script in order to make some kinds of calculation.
reduce_script & combine_script are very similar, but as combine script is working well, reduce, not.
I am using elasticsearch : 6.6.0 , could this be considered as a bug, or something i did not understand ?
thx
rgds
Nicolas