# Contains() function in Scripted field of Kibana

**URL:** <https://discuss.elastic.co/t/contains-function-in-scripted-field-of-kibana/146311>\
**Category:** Kibana\
**Created:** [August 28, 2018, 9:51am UTC](https://discuss.elastic.co/t/contains-function-in-scripted-field-of-kibana/146311 "2018-08-28T09:51:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![groverjatin17](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/groverjatin17/32/34657_2.png) [@groverjatin17](https://discuss.elastic.co/u/groverjatin17)\
**Post date:** [August 28, 2018, 9:51am UTC](https://discuss.elastic.co/t/contains-function-in-scripted-field-of-kibana/146311/1 "2018-08-28T09:51:05Z")

</div>

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"  
}

---

<div class="post-metadata">

**Author:** ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)\
**Post date:** [August 28, 2018, 12:25pm UTC](https://discuss.elastic.co/t/contains-function-in-scripted-field-of-kibana/146311/2 "2018-08-28T12:25:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 25, 2018, 12:25pm UTC](https://discuss.elastic.co/t/contains-function-in-scripted-field-of-kibana/146311/3 "2018-09-25T12:25:25Z")

</div>

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