I am converting an Elasticsearch script from Groovy to Painless. The script accepts a parameter, which can be either an integer or a string convertible to an integer (i.e. could be either 123 or "123").
In Groovy, doing my_val.toLong() converted both just fine, but that method is not available in Painless.
Is there any alternative syntax that would do the same in Painless?
I tried explicit casting with (long) my_var, but I get java.lang.String cannot be cast to java.lang.Number
In short, I want to do the following in Painless and to get true as a result:
GET _search
{
"script_fields": {
"test": {
"script": {
"lang": "groovy",
"params": {
"my_val1": "123",
"my_val2": 123
},
"source": """
my_val1.toLong() == my_val2.toLong()
"""
}
}
}
}