# Can we use split processor with painless scripting

**URL:** <https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536>\
**Category:** Elasticsearch\
**Created:** [August 28, 2017, 10:20am UTC](https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536 "2017-08-28T10:20:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinay\_garg](https://avatars.discourse-cdn.com/v4/letter/v/8dc957/32.png) [@vinay\_garg](https://discuss.elastic.co/u/vinay_garg)\
**Post date:** [August 28, 2017, 10:20am UTC](https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536/1 "2017-08-28T10:20:53Z")

</div>

Hi,

Can we use split processor with painless scripting as we can use in java or groovy?

value of RequestIntime = "ReqestIn\_2017-08-21T12:10:10"  
def String request = doc['RequestInTime'].value;

Seperator shoud be based on "\_"(underscore).

is to possible to split  
[request][0] = "ReqestIn"  
[request][1] = "2017-08-21T12:10:10"

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [August 28, 2017, 6:44pm UTC](https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536/2 "2017-08-28T18:44:15Z")

</div>

You can split using the regex syntax.

```auto
String[] parts = /_/.split(request)

```

String.split is not available because it compiles a regex. In Painless, regexes are a feature that can be disabled, and also statically compiled (thus the special syntax using the "slashy string" to get a Pattern object above.

---

<div class="post-metadata">

**Author:** ![vinay\_garg](https://avatars.discourse-cdn.com/v4/letter/v/8dc957/32.png) [@vinay\_garg](https://discuss.elastic.co/u/vinay_garg)\
**Post date:** [August 29, 2017, 3:06am UTC](https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536/3 "2017-08-29T03:06:14Z")

</div>

Hi There,

I have enable regex pattern in elasticsearch.yml.  
I'm trying to use regex syntax as mention below:

String[] parts = /\_/.split(doc['RequestInTime.keyword'].value);  
List value = Arrays.asList(parts);  
String val = value[1];  
return val;

While updating the scripting fields, I'm getting compilation error.  
Caused by: java.text.ParseException: unexpected character '[' on line (1) position (6)  
Caused by: org.antlr.v4.runtime.LexerNoViableAltException

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [August 29, 2017, 4:05am UTC](https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536/4 "2017-08-29T04:05:13Z")

</div>

Lists don't have an array syntax. Just index the array directly, no need to turn it into a list.

```auto
String[] parts = /_/.split(doc[‘RequestInTime.keyword’].value);
return parts[1];

```

---

<div class="post-metadata">

**Author:** ![vinay\_garg](https://avatars.discourse-cdn.com/v4/letter/v/8dc957/32.png) [@vinay\_garg](https://discuss.elastic.co/u/vinay_garg)\
**Post date:** [August 29, 2017, 4:16am UTC](https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536/5 "2017-08-29T04:16:23Z")

</div>

Hey,

Thanks for such help.  
It's working. Earlier I'd tried same but it's not working. May be it's not reflected But now it reflects and working fine.

---

<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:** [September 26, 2017, 4:20am UTC](https://discuss.elastic.co/t/can-we-use-split-processor-with-painless-scripting/98536/6 "2017-09-26T04:20:29Z")

</div>

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