Elasticsearch version: 5.0.0-rc1 in the elastic cloud
Plugins installed: []
JVM version:
OS version:
Description of the problem including expected versus actual behavior:
Steps to reproduce:
curl -XPOST foo/user/user1 -d '{
"businesses_reviewed" : []
}'
curl -XPOST 'foo/user/user1/_update?pretty' -d '{
"script": {
"inline": "ctx._source.businesses_reviewed += params.businessid_name",
"lang": "painless",
"params": {
"businessid_name": "zJyvOekrI4Z6bajVp5Etlg Sidestreet Pho and Grill"
}
}
}'
Provide logs (if relevant):
{
"error" : {
"root_cause" : [
{
"type" : "remote_transport_exception",
"reason" : "[instance-0000000002][10.232.142.5:19955][indices:data/write/update[s]]"
}
],
"type" : "illegal_argument_exception",
"reason" : "failed to execute script",
"caused_by" : {
"type" : "script_exception",
"reason" : "runtime error",
"caused_by" : {
"type" : "class_cast_exception",
"reason" : "Cannot cast java.lang.String to java.util.ArrayList"
},
"script_stack" : [
"ctx._source.businesses_reviewed += params.businessid_name",
" ^---- HERE"
],
"script" : "ctx._source.businesses_reviewed += params.businessid_name",
"lang" : "painless"
}
},
"status" : 400
}
Describe the feature:
This looks like an issue with the def type making assumptions about the left-hand side type based on the right-hand side type without recognizing that there's a potential type mismatch for overloaded operators.
Work around for this issue is to just call the method on the List rather than the shortcut.
if (ctx._source.businesses_reviewed == null) {
ctx._source.businesses_reviewed = new ArrayList();
}
ctx._source.businesses_reviewed.add(params.businessid_name);
Okay, so technically this isn't a bug as we don't support this shortcut operator for lists currently. If this feature is required moving forward, please re-open this issue as a feature request.
Well, it was supported in the old scripting language, I thought the point of painless in this release was to basically work for old scripts at least for functionality that isn't insecure?
On another note, is there docs for this? Or is that example up above basically just java code running and I can do anything that java can do?
I added this enhancement request here:
Painless' primary goal was security with a secondary goal of performance. We did not have time to add all the features of Groovy (nor should we), and each one must be considered relative to the goals of the project. Having a list shortcut will actually require all compound additions to have a check against def types since addition is expected to return a value where adding a value to a list would return void. This causes a performance hit. Compound assignment will still work against values in a list, though, which is a shortcut in of itself.
As for documentation, it needs to be improved significantly. For the most part Painless is somewhere in between Groovy and Java, so if a Groovy feature doesn't work, it's safe to give the Java way a try.
Most helpful comment
Work around for this issue is to just call the method on the List rather than the shortcut.