I am trying to create string from bytes in Painless script, as below, but ending up with error around new
keyword. Our Elasticsearch is 6.2.8.
(Length check at the end is just for brevity so the script returns boolean.)
{
"size": 1,
"query": {
"bool" : {
"filter" : {
"script" : {
"script" : {
"source": "byte[] a = new byte[]{65, 66, 67}; String b = new String(a, StandardCharsets.UTF_8); b.length() > 0",
"lang": "painless"
}
}
}
}
}
}
Error as below:
"script_stack": [
"... {65, 66, 67}; String b = new String(a, StandardCha ...",
" ^---- HERE"
],
"lang": "painless",
"type": "illegal_argument_exception",
"reason": "Unknown new call on type [java.lang.String]."
I have to admit I am confused. This is my first adventure with Painless but I saw dozens of examples with new
keyword in them. Documentation clearly states that this is the way. Duh, it is even in the same script above. What am I missing? Why it is OK to create array but not string?