Split on Token not found in kibana

1.5k views Asked by At

I am trying to split string with comma in kibana painless script as below:

def skillid = doc['skillid.keyword'].value;

List lstskills = new ArrayList();

lstskills = skillid.splitOnToken(',');

With this,i am getting error as : dynamic method [java.lang.string splitOnToken/1]not found.

Is there any way to split string in kibana without using split function? And is regex safe to use in kibana script?

1

There are 1 answers

0
Ankit Satpute On

This simplified version might work. Instead of creating a separate variable you can directly apply splitOnToken(str) method. Also, you need not create a separate list if you want to save the result in a separate field on ES, as it automatically returns the list after splitting and you can assign the result to a field on which you want to store the result. In case

Worked for me in elasticsearch-7.9.3

Your code like this should work:

doc['newField'] = doc['skillid.keyword'].splitOnToken(',');