# Unable to split Strings in Painless

**URL:** <https://discuss.elastic.co/t/unable-to-split-strings-in-painless/170164>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 27, 2019, 12:29pm UTC](https://discuss.elastic.co/t/unable-to-split-strings-in-painless/170164 "2019-02-27T12:29:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaustubh\_Pardeshi](https://avatars.discourse-cdn.com/v4/letter/k/3bc359/32.png) [@Kaustubh\_Pardeshi](https://discuss.elastic.co/u/Kaustubh_Pardeshi)\
**Post date:** [February 27, 2019, 12:29pm UTC](https://discuss.elastic.co/t/unable-to-split-strings-in-painless/170164/1 "2019-02-27T12:29:01Z")

</div>

Hi, I am having trouble splitting a string using painless to create a new field. I have a string like:  
doc['path.keyword'].value = 'N:/divtaxbacktest/Comp/divbacktest/SMEA.L.csv';

And I would like to extract SMEA.L, so I am trying to first split the string and use substring as such:  
String parts = ///.split(doc['path'].value);  
return parts[3].substring( 0, -4 );

But it is not working. Could someone please help?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2019, 12:47pm UTC](https://discuss.elastic.co/t/unable-to-split-strings-in-painless/170164/2 "2019-02-27T12:47:38Z")

</div>

Are you doing that in an ingest pipeline ?

---

<div class="post-metadata">

**Author:** ![Kaustubh\_Pardeshi](https://avatars.discourse-cdn.com/v4/letter/k/3bc359/32.png) [@Kaustubh\_Pardeshi](https://discuss.elastic.co/u/Kaustubh_Pardeshi)\
**Post date:** [February 27, 2019, 12:50pm UTC](https://discuss.elastic.co/t/unable-to-split-strings-in-painless/170164/3 "2019-02-27T12:50:52Z")

</div>

Im trying to create a scripted field

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2019, 1:10pm UTC](https://discuss.elastic.co/t/unable-to-split-strings-in-painless/170164/4 "2019-02-27T13:10:52Z")

</div>

Ok. Please be aware that it will be slow in comparison of doing that at index time (using ingest or not).

May I ask what is your goal at the end?

Also could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<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:** [March 27, 2019, 1:10pm UTC](https://discuss.elastic.co/t/unable-to-split-strings-in-painless/170164/5 "2019-03-27T13:10:57Z")

</div>

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