Reverse of a list of strings in painless

How to call the reverse API in painless for a list of strings?

Basically I would like to do:

split()
reverse()
...

However, painless always complains there is no dynamic method reverse for string[].

Hi

It should be available dynamically, but it would be available on a List not an array. I don't think we provide much of an API for arrays and unfortunately split for string right now requires regular expressions, so the you will have to have those enabled. The other thing is we are working on improvements to the documentation, and while this doesn't cover your specific issue yet, it does cover types and operators more thoroughly

https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-specification.html

I will try again to see if there is any good way to solve this, but for now, this is what I have got.

Thanks
Rashmi

I finally made the java code working, and it requires significant type casting :frowning:

String[] aa;
aa = domain.split("\.");
List ss = Arrays.asList(aa);
Collections.reverse(ss);

However, translating the above pseudo Jave code into painless is a nightmare. Painless is far less from a working language and it would be great if the working Java code could work right away within painless.

By the way, how to write painless code across multiple lines?

Should I use:

Can I write:

if (x > 0) {
...
}
across three lines?

Hi

Can you please let us know which part of that code you wrote doesn't work in painless and provide errors. Also you can surely write it across multiple lines; however if you are using the JSON to make requests, you must make script JSON compatible (i don't think JSON allows for multiple lines in this way)

Thanks
Rashmi

doesn't work in painless

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