# How to pick range of splitted field in mutate filter

**URL:** <https://discuss.elastic.co/t/how-to-pick-range-of-splitted-field-in-mutate-filter/248656>\
**Category:** Logstash\
**Created:** [September 15, 2020, 10:38am UTC](https://discuss.elastic.co/t/how-to-pick-range-of-splitted-field-in-mutate-filter/248656 "2020-09-15T10:38:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dorinand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dorinand/32/70521_2.png) [@dorinand](https://discuss.elastic.co/u/dorinand)\
**Post date:** [September 15, 2020, 10:38am UTC](https://discuss.elastic.co/t/how-to-pick-range-of-splitted-field-in-mutate-filter/248656/1 "2020-09-15T10:38:04Z")

</div>

I generate field on input:

```
input {
  generator {
    add_field => {
      "[kubernetes][pod][name]" => "aaaa-bbbb-a1b2c3"
    }
    count => 1
  }
}

```

I need to remove last part of pod name `a1b2c3`. Iam trying to split it and pick the range from 0 to -1 but it does not work.

```
filter {
  mutate {
    split => ["[kubernetes][pod][name]", "-"]
    add_field => { "[@metadata][index]" => "%{[kubernetes][pod][name][0:-1]}" }
  }
}

```

Is it possible to pick range of indices? Is there better way how to do it? The reason is, i am harversting logs from kubernetes and I would like to use rollover indices. Then, I have to keep consistent indices names. Kubernetes unfortunatelly change the hash part so I have to remove it from name. Thank you.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [September 15, 2020, 1:33pm UTC](https://discuss.elastic.co/t/how-to-pick-range-of-splitted-field-in-mutate-filter/248656/2 "2020-09-15T13:33:35Z")

</div>

If you just want the last entry in an array I would use

```
%{[kubernetes][pod][name][-1]}
```

---

<div class="post-metadata">

**Author:** ![dorinand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dorinand/32/70521_2.png) [@dorinand](https://discuss.elastic.co/u/dorinand)\
**Post date:** [September 16, 2020, 7:44am UTC](https://discuss.elastic.co/t/how-to-pick-range-of-splitted-field-in-mutate-filter/248656/3 "2020-09-16T07:44:43Z")

</div>

Hi, thank you for your reply. I know how to pick exact index, but I need to pick all except last one.

---

<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:** [October 14, 2020, 7:44am UTC](https://discuss.elastic.co/t/how-to-pick-range-of-splitted-field-in-mutate-filter/248656/4 "2020-10-14T07:44:49Z")

</div>

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