# I have problem when using painless

**URL:** <https://discuss.elastic.co/t/i-have-problem-when-using-painless/282630>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [August 27, 2021, 5:33am UTC](https://discuss.elastic.co/t/i-have-problem-when-using-painless/282630 "2021-08-27T05:33:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aniwer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aniwer/32/93805_2.png) [@Aniwer](https://discuss.elastic.co/u/Aniwer)\
**Post date:** [August 27, 2021, 5:33am UTC](https://discuss.elastic.co/t/i-have-problem-when-using-painless/282630/1 "2021-08-27T05:33:43Z")

</div>

The following is my data in es, the right is the message that I use journalbeat to import and i want to be processed, the left is the result processed by painless

 ![6F4C677EA824B55BCD813EAB8C9FFB60](https://us1.discourse-cdn.com/elastic/original/3X/9/3/9393620a1ae8f07a550ae596b0f7b57d609718c2.png)  
The following is the painless i wrote

```auto
if(doc['message.keyword'].size() > 0 ){

    def processMsg = doc['message.keyword'].value;
    if (processMsg != null && processMsg.contains("finished upload/dip job of unit")){
         return processMsg
    }
    // String splitter = " "; 
    // ArrayList array=new ArrayList(); 
    // StringTokenizer tokenValue = new StringTokenizer(processMsg, splitter); 
    // while (tokenValue.hasMoreTokens()) { array.add(tokenValue.nextToken()); }
    // return Integer.parseInt(array[array.length()-2])
}
return 0

```

Actually, i want to get the data from message between the word "in" and the word "seconds", but when i use 'contains' filter the message, It doesn't always work.  
I don't know how to write, please help me. 😭

---

<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:** [August 30, 2021, 8:52pm UTC](https://discuss.elastic.co/t/i-have-problem-when-using-painless/282630/2 "2021-08-30T20:52:56Z")

</div>

It looks like the code is not always getting to line 5. There are 3 places where the code could be jumping out of the block and returning 0.

- What if you try returning different integers on different lines, to help yourself understand how far each document is able to get through the code?

- Is it possible there are space characters in the data that are hiding in your browser? What if you add multiple checks on less specific sequences of strings? e.g:

---

<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 27, 2021, 8:52pm UTC](https://discuss.elastic.co/t/i-have-problem-when-using-painless/282630/3 "2021-09-27T20:52:59Z")

</div>

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