# Script index field check if string starts with

**URL:** <https://discuss.elastic.co/t/script-index-field-check-if-string-starts-with/49654>\
**Category:** Elasticsearch\
**Created:** [May 10, 2016, 1:03pm UTC](https://discuss.elastic.co/t/script-index-field-check-if-string-starts-with/49654 "2016-05-10T13:03:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalogger](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@dalogger](https://discuss.elastic.co/u/dalogger)\
**Post date:** [May 10, 2016, 1:03pm UTC](https://discuss.elastic.co/t/script-index-field-check-if-string-starts-with/49654/1 "2016-05-10T13:03:30Z")

</div>

I am trying to define a new scripted index field that will check if a index field starts with a certain value. If so then a certain string value is returned.

if ( doc['request'].value starts with "/MyApp/" ) return "MyApp";  
else if ( doc['request'].value starts with "/AnotherApp/" ) return "AnotherApp";

The doc['request'] field is actually the request from an Apache HTTP log. The first portion is always going to be the application name.

In the end, I am trying to determine which application is used the most and with a scripted field like this I should be able to make such a visualization.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 11, 2016, 11:24pm UTC](https://discuss.elastic.co/t/script-index-field-check-if-string-starts-with/49654/2 "2016-05-11T23:24:37Z")

</div>

Are you just trying to remove the `/` type values here, or is there more too it?

---

<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:** [July 5, 2017, 10:52pm UTC](https://discuss.elastic.co/t/script-index-field-check-if-string-starts-with/49654/3 "2017-07-05T22:52:21Z")

</div>


