No_viable_alt_exception in painless script field

Hi All,
I want to calculate a substring of a string field (starting from 0 till either a fixed position or till - symbol ) under kibana index pattern . However when I am trying to create a scripted field I am getting "Script is invalid" error

My script -
def tempVal = doc['fieldname.keyword'].value;
if(tempVal != null)
def FormattedVal = tempVal .subString(0, 6);
return FormattedVal ;

Error details (under preview result) -
"script": "def tempVal = doc['fieldname.keyword'].value; ...",
"lang": "painless",
"position": {
"offset": 143,
"start": 120,
"end": 178
"caused_by": {
"type": "illegal_argument_exception",
"reason": "dynamic method [java.lang.String, subString/2] not found"

Kindly assist.
Thanks in advance !

try substring with a lower case S

Thanks , issue is resolved.

1 Like

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