# Indexof and substring on custom field on kibana version 5.6

**URL:** <https://discuss.elastic.co/t/indexof-and-substring-on-custom-field-on-kibana-version-5-6/184197>\
**Category:** Elasticsearch\
**Created:** [June 4, 2019, 1:35pm UTC](https://discuss.elastic.co/t/indexof-and-substring-on-custom-field-on-kibana-version-5-6/184197 "2019-06-04T13:35:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joey\_Lam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joey_lam/32/47285_2.png) [@Joey\_Lam](https://discuss.elastic.co/u/Joey_Lam)\
**Post date:** [June 4, 2019, 1:35pm UTC](https://discuss.elastic.co/t/indexof-and-substring-on-custom-field-on-kibana-version-5-6/184197/1 "2019-06-04T13:35:41Z")

</div>

I am currently using kibana version 5.6.

I would like to

1. search the position of string in a field and then
2. extract the substring from the field
3. show to value on "Discover"

Code Example:

def x = doc["description"].value  
if (x != null) {  
int pos = x.indexof("start")  
if (pos \> 0) {  
return x.substring(pos, 20)  
}  
}  
return "not found"

currently, pos is alway 0.

---

<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 2, 2019, 1:35pm UTC](https://discuss.elastic.co/t/indexof-and-substring-on-custom-field-on-kibana-version-5-6/184197/2 "2019-07-02T13:35:54Z")

</div>

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