Search code examples
elasticsearch-painless

Reverse a string in KIBANA/painless


I'm not able to reverse a string in KIBANA/painless (section: scripted fields)

def foo = ('dlroW olleH');
return foo.reverse();

I expect the output of "Hello World", but KIBANA sais "No results found". If i do a "return foo;" it works well - on every outputline "dlroW olleH" is shown.

Can anyone give me a hint, where the problem is?

EDIT: kibana 5.6, regexp for painless is disabled


Solution

  • .reverse() isn't a listed method to operate on a String object [1]; it's available to operate a StringBuffer object. [2]

    You can make a StringBuffer and call reverse on it.

    StringBuffer foo = new StringBuffer('dlroW olleH');
    foo.reverse();
    return foo.toString();