Split Function in Painless

Hi-
I have a field name (Testjob/admin/pipeline#1) getting injected in the Elasticsearch, I'd like to split the field name by ('/') and take the last index value which is (pipeline#1) and show the field names on the graphs. Am trying to put this in the JSON Input on the Visualization using painless, the split doesn't work.
Any other suggestions. Could someone please help.

{
"script": "_value.split('/')[2]",
"lang": "painless"
}

Hey @paul1243,

Your script is very close (I'm actually surprised that syntax doesn't work...).
My script uses a regular expression, which requires you to set script.painless.regex.enabled: true in your elasticsearch.yml file:

My example (replace 'field.keyword' with your field name):

/\//.split(doc['field.keyword'].value)[2]

I created a "Scripted Field" in Kibana using this script, and it works as expected:
image

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