# Access array element after split processor

**URL:** <https://discuss.elastic.co/t/access-array-element-after-split-processor/90539>\
**Category:** Elasticsearch\
**Created:** [June 22, 2017, 8:54pm UTC](https://discuss.elastic.co/t/access-array-element-after-split-processor/90539 "2017-06-22T20:54:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hding](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hding](https://discuss.elastic.co/u/hding)\
**Post date:** [June 22, 2017, 8:54pm UTC](https://discuss.elastic.co/t/access-array-element-after-split-processor/90539/1 "2017-06-22T20:54:39Z")

</div>

I'm trying to access array element after splitting a string into array using a 'split' processor in an ingest node pipeline?

I have a long string separated by slash ('/'). I only want to pass one substring to index, and dump the rest.

For example, I have a string "/aaa/bbb/ccc". I only want to index "ccc".

My current idea is to use split + set + remove, but I don't know how to access the array element after splitting.

---

<div class="post-metadata">

**Author:** ![hding](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hding](https://discuss.elastic.co/u/hding)\
**Post date:** [June 23, 2017, 1:01pm UTC](https://discuss.elastic.co/t/access-array-element-after-split-processor/90539/2 "2017-06-23T13:01:45Z")

</div>

It looks to me there has to be a solution. But I can't find it anywhere.

I've tried {{array}}[3], {{array[3]}}, {{array}[3]}, {{array}}.values[3], doc['array'].values[3]. None of them works.

---

<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:** [June 26, 2017, 9:40pm UTC](https://discuss.elastic.co/t/access-array-element-after-split-processor/90539/3 "2017-06-26T21:40:58Z")

</div>

Try using a script processor. Your script could look something like this (eg for the first element):

```auto
"script": "ctx._source['myfield'] = ctx._source['myfield'].split('/')[0]"

```

---

<div class="post-metadata">

**Author:** ![hding](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@hding](https://discuss.elastic.co/u/hding)\
**Post date:** [June 27, 2017, 12:43pm UTC](https://discuss.elastic.co/t/access-array-element-after-split-processor/90539/4 "2017-06-27T12:43:06Z")

</div>

Thanks a lot, Ryan.

---

<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:** [July 25, 2017, 12:43pm UTC](https://discuss.elastic.co/t/access-array-element-after-split-processor/90539/5 "2017-07-25T12:43:24Z")

</div>

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