# Split Function in Painless

**URL:** <https://discuss.elastic.co/t/split-function-in-painless/204728>\
**Category:** Kibana\
**Created:** [October 22, 2019, 8:22pm UTC](https://discuss.elastic.co/t/split-function-in-painless/204728 "2019-10-22T20:22:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul1243](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@paul1243](https://discuss.elastic.co/u/paul1243)\
**Post date:** [October 22, 2019, 8:22pm UTC](https://discuss.elastic.co/t/split-function-in-painless/204728/1 "2019-10-22T20:22:55Z")

</div>

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"  
}

---

<div class="post-metadata">

**Author:** ![Larry\_Gregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/larry_gregory/32/34969_2.png) [@Larry\_Gregory](https://discuss.elastic.co/u/Larry_Gregory)\
**Post date:** [October 23, 2019, 12:02pm UTC](https://discuss.elastic.co/t/split-function-in-painless/204728/2 "2019-10-23T12:02:44Z")

</div>

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):

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

```

I created a "Scripted Field" in Kibana using this script, and it works as expected:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/9/890347fd05e00b828ae4a1ed4d6d57454ec953a2.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 20, 2019, 12:02pm UTC](https://discuss.elastic.co/t/split-function-in-painless/204728/3 "2019-11-20T12:02:47Z")

</div>

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