Can we use split processor with painless scripting

Hi,

Can we use split processor with painless scripting as we can use in java or groovy?

value of RequestIntime = "ReqestIn_2017-08-21T12:10:10"
def String request = doc['RequestInTime'].value;

Seperator shoud be based on "_"(underscore).

is to possible to split
[request][0] = "ReqestIn"
[request][1] = "2017-08-21T12:10:10"

You can split using the regex syntax.

String[] parts = /_/.split(request)

String.split is not available because it compiles a regex. In Painless, regexes are a feature that can be disabled, and also statically compiled (thus the special syntax using the "slashy string" to get a Pattern object above.

Hi There,

I have enable regex pattern in elasticsearch.yml.
I'm trying to use regex syntax as mention below:

String[] parts = /_/.split(doc['RequestInTime.keyword'].value);
List value = Arrays.asList(parts);
String val = value[1];
return val;

While updating the scripting fields, I'm getting compilation error.
Caused by: java.text.ParseException: unexpected character '[' on line (1) position (6)
Caused by: org.antlr.v4.runtime.LexerNoViableAltException

Lists don't have an array syntax. Just index the array directly, no need to turn it into a list.

String[] parts = /_/.split(doc[‘RequestInTime.keyword’].value);
return parts[1];

Hey,

Thanks for such help.
It's working. Earlier I'd tried same but it's not working. May be it's not reflected But now it reflects and working fine.

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