# String manipulation in painless script

**URL:** https://discuss.elastic.co/t/string-manipulation-in-painless-script/65239
**Category:** Elasticsearch
**Created:** [November 7, 2016, 3:16pm UTC](https://discuss.elastic.co/t/string-manipulation-in-painless-script/65239 "2016-11-07T15:16:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ahmmum](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ahmmum](https://discuss.elastic.co/u/ahmmum)
#### Post date: [November 7, 2016, 3:16pm UTC](https://discuss.elastic.co/t/string-manipulation-in-painless-script/65239/1 "2016-11-07T15:16:48Z")

</div>

I need to compute some scores using query string and title of a document, which are not exposed by elasticsearch. I need to split a string to a list as follows: 'applie pie' --\> ['apple', 'pie'] . I am using custom script scoring by painless scripts.

How can I do that?

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [November 7, 2016, 4:46pm UTC](https://discuss.elastic.co/t/string-manipulation-in-painless-script/65239/2 "2016-11-07T16:46:46Z")

</div>

Hey,

you can try sth like `"ctx._source.foo = /,/.split(ctx._source.foo)"` - but this requires you to explicitely enable regexes, as those are not considered secure.

--Alex

---

<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: [December 6, 2016, 10:11pm UTC](https://discuss.elastic.co/t/string-manipulation-in-painless-script/65239/4 "2016-12-06T22:11:08Z")

</div>

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