# Check if a field string start with a determinate string

**URL:** <https://discuss.elastic.co/t/check-if-a-field-string-start-with-a-determinate-string/108612>\
**Category:** Kibana\
**Created:** [November 21, 2017, 8:05pm UTC](https://discuss.elastic.co/t/check-if-a-field-string-start-with-a-determinate-string/108612 "2017-11-21T20:05:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [November 21, 2017, 8:20pm UTC](https://discuss.elastic.co/t/check-if-a-field-string-start-with-a-determinate-string/108612/2 "2017-11-21T20:20:44Z")

</div>

Try this:

```auto
def path = doc['myField'].value;
if (path != null) {
    int loc = path.indexOf('edi');
    if (loc == 0) {
      return 'EDI';
    }
}
return null;

```

The `myField` field must be a keyword type (or use `myField.keyword` if you have the multi-field).

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/1/71b75ca2c4d8b2c7cd6101fce436cbac72b70c02.png)

Personally, if the field is going to either be a certain value or not, I would probably return Booleans from my script, and call the field `isEdi`

---

_[View the full topic](https://discuss.elastic.co/t/check-if-a-field-string-start-with-a-determinate-string/108612)._
