# Using painless script split(string) don't work

**URL:** <https://discuss.elastic.co/t/using-painless-script-split-string-dont-work/90215>\
**Category:** Kibana\
**Created:** [June 21, 2017, 7:47am UTC](https://discuss.elastic.co/t/using-painless-script-split-string-dont-work/90215 "2017-06-21T07:47:30Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [June 26, 2017, 4:43pm UTC](https://discuss.elastic.co/t/using-painless-script-split-string-dont-work/90215/4 "2017-06-26T16:43:10Z")

</div>

I got curious how to do this, so I downloaded the Groovy SDK (since Painless is very similar to Groovy) and played around with some test code in Groovy Console:

 ![](https://us1.discourse-cdn.com/elastic/original/3X/9/d/9dfb02f8bc7f4a3916a7872809dbdb2256668d6d.png)

Maybe this will work for you:

```auto
def dom = doc['domain'].value;
String[] level = dom.split(/\./); // split the string per regex
List ss = Arrays.asList(level);
String l2 = ss[1]; // 1-th index is the "second" level
return l2;

```

---

_[View the full topic](https://discuss.elastic.co/t/using-painless-script-split-string-dont-work/90215)._
