I have a string field "myfield.keyword", where each entry has the following format:
AAA_BBBB_CC
DDD_EEE_F
I am trying to create a scripted field that outputs the substring before the first _, a scripted field that outputs the substring between the first and second _ and a scripted field that outputs the substring after the second _
This outputs the result I want, because the subtring before the first _ always has three characters. However, I cannot generalise this approach to the other scripted fields, because the lenghts of the relevant substrings varies between different entries. I suppose that the strategy should be using "_" as a delimiter for the different outputs, but I haven't been able to find a suitable solution.
Thanks Joe!
I am trying to use path.split('_') as you suggested but haven't been able to get it right. My idea is to use this same approach for the different elements of the array. For instance:
When the if condition is satisfied, the output of client is 3, as expected. However, this is not general enough and I still haven't been able to make a script with path.split('_'). Any ideas? Idealy, I would need to create an array as a result of spliting a string, with _ as the delimiter and then call the diferent elements of the array.
No worries
The workaround didn't work for me. I get an error of type "illegal_state_exception" and reason: "Regexes are disabled..." I am wondering if there's a way to split a string that does not involve enabling regexes (since that's not an option for me)
In case this might be useful for someone else, I finally managed to solve the problem by employing path.indexOf('_') and a few more things. This solution can be adapated for any number of splits. That is, in my case, I had to split a string into 5 different parts, given four occurrences of _. This solution can be adaptad for any other number of parts.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.