I have problem when using painless

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


The following is the painless i wrote

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. :sob:

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:

    if (processMsg != null && processMsg.contains("finished upload") && processMsg.contains("dip job of unit")){

    Or try some different tests along those lines.

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