Is there a way to use java.util.regex.Pattern in a painless script? I get an error:
curl -i -XPOST http://localhost:9200/_scripts/painless/_execute -H 'Content-type: application/json' --data-binary '{"script": {"source": "return java.util.regex.Pattern.matches(\"a*b\",\"aaab\");", "params": { "test":1 } } }'
HTTP/1.1 500 Internal Server Error
content-type: application/json; charset=UTF-8
content-length: 668
{"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["... n java.util.regex.Pattern.matches(\"a*b\",\"aaab\");"," ^---- HERE"],"script":"return java.util.regex.Pattern.matches(\"a*b\",\"aaab\");","lang":"painless"}],"type":"script_exception","reason":"compile error","script_stack":["... n java.util.regex.Pattern.matches(\"a*b\",\"aaab\");"," ^---- HERE"],"script":"return java.util.regex.Pattern.matches(\"a*b\",\"aaab\");","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"method [java.util.regex.Pattern, matches/2] not found"}},"status":500}
Other java.util classes seem to work:
curl -i -XPOST http://localhost:9200/_scripts/painless/_execute -H 'Content-type: application/json' --data-binary '{"script": {"source": "new java.util.BitSet(10).length();", "params": { "test":1 } } }'
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 14
{"result":"0"}
I know there is built-in regex support but that requires the pattern be a literal, hard-coded string. A native script I'm trying to port to painless needs to use a regex pattern string passed as a parameter.