# Searching for an expression inside a field and returning the information that comes after

**URL:** <https://discuss.elastic.co/t/searching-for-an-expression-inside-a-field-and-returning-the-information-that-comes-after/166360>\
**Category:** Elasticsearch\
**Created:** [January 30, 2019, 1:17pm UTC](https://discuss.elastic.co/t/searching-for-an-expression-inside-a-field-and-returning-the-information-that-comes-after/166360 "2019-01-30T13:17:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelogabeira](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@angelogabeira](https://discuss.elastic.co/u/angelogabeira)\
**Post date:** [January 30, 2019, 1:17pm UTC](https://discuss.elastic.co/t/searching-for-an-expression-inside-a-field-and-returning-the-information-that-comes-after/166360/1 "2019-01-30T13:17:13Z")

</div>

I have an index which has a field 'description' with some text. I want to search for a pattern in this field (ex: Error Message: XXXXXXX) and I want to return the text after it but have not been able to accomplish this yet.

I used the code below but the result is not what was expected.

def path = doc['descricao'].value;  
int a = path.indexOf("error" );  
int b = path.indexOf("Error" );  
if (a \> 0) { return path.substring(a);}  
else if (b \> 0) {return path.substring(b);}  
else {return "";}

Any ideas of how I can accomplish this?

Aside from the Painless script language, is there any other way to do it?

Thanks.

---

<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:** [February 27, 2019, 1:17pm UTC](https://discuss.elastic.co/t/searching-for-an-expression-inside-a-field-and-returning-the-information-that-comes-after/166360/2 "2019-02-27T13:17:18Z")

</div>

Closed on February 27, 2019, 1:17pm UTC

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