# Runtime field painless script to extract from a field

**URL:** <https://discuss.elastic.co/t/runtime-field-painless-script-to-extract-from-a-field/327696>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [March 14, 2023, 7:03pm UTC](https://discuss.elastic.co/t/runtime-field-painless-script-to-extract-from-a-field/327696 "2023-03-14T19:03:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zx8086](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zx8086/32/94917_2.png) [@zx8086](https://discuss.elastic.co/u/zx8086)\
**Post date:** [March 14, 2023, 7:03pm UTC](https://discuss.elastic.co/t/runtime-field-painless-script-to-extract-from-a-field/327696/1 "2023-03-14T19:03:18Z")

</div>

Hi

Have a field named path with content "first\_part/second\_part/third\_part" and what to extract the first\_part with a painless script

Thanks

---

<div class="post-metadata">

**Author:** ![zx8086](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zx8086/32/94917_2.png) [@zx8086](https://discuss.elastic.co/u/zx8086)\
**Post date:** [March 15, 2023, 12:05am UTC](https://discuss.elastic.co/t/runtime-field-painless-script-to-extract-from-a-field/327696/2 "2023-03-15T00:05:51Z")

</div>

```auto
emit(source.splitOnToken('/')[0])

```

---

<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:** [April 12, 2023, 12:06am UTC](https://discuss.elastic.co/t/runtime-field-painless-script-to-extract-from-a-field/327696/3 "2023-04-12T00:06:17Z")

</div>

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