Painless script functions

I wrote a function that returns an ArrayList from an expression passed in a parameter. The function is the first line of a stored script that is called from a watcher.

When testing the watcher that calls this stored script (with the function), it doesn't return at all and eventually times out. Without the function it returns quickly.

Is there anything that would explain this behavior within Kibana painless? The documentation is very light on functions.

@Matt_McGovern

Painless is evaluated on Elasticsearch. There might not be enough expertise here on this Kibana forum to help with this question.

Thanks for replying...I wanted to post here first before asking in a ticket.

There was no problem with the function (below)...we were having other problems which caused the timeout. I'm posting this function because I haven't seen much discussion about kibana script functions in painless, and I've seen a lot of people asking for the Split function.

ArrayList Split(String str, String delimiter){String term='';boolean delAtEnd=false;ArrayList exprArray = new ArrayList();if(str.indexOf(delimiter)>0){for(int x=0;x<str.length();++x){if(str.substring(x,x+1)==delimiter){exprArray.add(term);term='';if(x+1==str.length()){delAtEnd = true;}}else{term+=str.substring(x,x+1);}}if (delAtEnd == false){exprArray.add(term);}}return exprArray;}
String debugMsg = '\n';
ArrayList testArray = Split('expr1^expr2^expr3','^');
for(int x=0;x<testArray.length;++x)
{
if(x>0)
{
debugMsg+='\n';
}
debugMsg+=testArray.get(x)
}

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