Contains() function in Scripted field of Kibana

Hi,

I am trying to create a scripted field(Painless) based on the if condition on the present Field.
The criteria is if a field(suppose "Name") contains "sammy" as a value.

I want to check if the value contains "am" as a substring so it can enter the if condition.
Just like IndexOf, i tried using contains function of java.
I tried to using it, although it does not return any error it still gives empty values.

Eg:-
if(doc['Name'].value.contains("am")){
return "success"
}

For me this script works. I have set up the mapping for the index it is running against so that the Name field is mapped as a keyword type. Maybe you have no values that contain "am"? If you want no empty values for this field, you should add an else.