# Painless script functions

**URL:** <https://discuss.elastic.co/t/painless-script-functions/170070>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 26, 2019, 9:09pm UTC](https://discuss.elastic.co/t/painless-script-functions/170070 "2019-02-26T21:09:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_McGovern](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_mcgovern/32/90131_2.png) [@Matt\_McGovern](https://discuss.elastic.co/u/Matt_McGovern)\
**Post date:** [February 26, 2019, 9:09pm UTC](https://discuss.elastic.co/t/painless-script-functions/170070/1 "2019-02-26T21:09:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)\
**Post date:** [February 27, 2019, 6:12pm UTC](https://discuss.elastic.co/t/painless-script-functions/170070/2 "2019-02-27T18:12:49Z")

</div>

@Matt_McGovern

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

---

<div class="post-metadata">

**Author:** ![Matt\_McGovern](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_mcgovern/32/90131_2.png) [@Matt\_McGovern](https://discuss.elastic.co/u/Matt_McGovern)\
**Post date:** [February 27, 2019, 6:48pm UTC](https://discuss.elastic.co/t/painless-script-functions/170070/3 "2019-02-27T18:48:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matt\_McGovern](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_mcgovern/32/90131_2.png) [@Matt\_McGovern](https://discuss.elastic.co/u/Matt_McGovern)\
**Post date:** [March 1, 2019, 7:03pm UTC](https://discuss.elastic.co/t/painless-script-functions/170070/4 "2019-03-01T19:03:05Z")

</div>

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)  
}

---

<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:** [March 29, 2019, 7:03pm UTC](https://discuss.elastic.co/t/painless-script-functions/170070/5 "2019-03-29T19:03:17Z")

</div>

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