Replace all method is not working

"sort": [
{
"_script": {
"script": {
"source": "def varRating = 0; if(doc['symbol'].value == 'fac') varRating=1;else if(doc['name'].value == 'fac') varRating=2;else if(doc['name'].value.indexOf('fac') == 0) varRating=20;else if((doc['name'].value.replaceAll(' ', '').indexOf('fac') == 0) )varRating=20; varRating;",
"lang": "painless"
},
"type": "number",
"order": "asc"
}
},
{
"avdolv": {
"order": "desc"
}
},
{
"symbol": {
"order": "asc"
}
},
{
"name": {
"order": "asc"
}
}
]
throwing error
class_cast_exception: Cannot cast java.lang.String to java.util.function.Function
can any body tell me how to fix this query

Hey,

please format your messages properly. You can use markdown in this forum and you should to make your snippets way more readable.

Please take a look at the painless documentation as there is a short mention about the replaceAll method and why it takes function as the second argument.

--Alex

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.