# Split field and add new fields

**URL:** <https://discuss.elastic.co/t/split-field-and-add-new-fields/262571>\
**Category:** Logstash\
**Created:** [January 28, 2021, 9:48pm UTC](https://discuss.elastic.co/t/split-field-and-add-new-fields/262571 "2021-01-28T21:48:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtillman2020](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jtillman2020](https://discuss.elastic.co/u/jtillman2020)\
**Post date:** [January 28, 2021, 9:48pm UTC](https://discuss.elastic.co/t/split-field-and-add-new-fields/262571/1 "2021-01-28T21:48:53Z")

</div>

I have a string field named "One".

```auto
<165>Original Address=1.1.1.1 1 2021-01-28T15:08:03.136-05:00 DeviceName - - - - fpc3 DHCP Packet Drop: Packet src ip/mac 192.168.123.1/54:48:10:db:86:b6

```

I use

```auto
mutate {
     split => {"One" => " "}
}

```

To split on the space. Which looks like this:

```auto
<165>Original, Address=1.1.1.1, Jan, 28, 16:38:42, DeviceName, fpc3, DHCP, Packet, Drop:, Packet, src, ip/mac, 192.168.123.1/54:48:10:db:86:b6

```

I then use

```auto
mutate {
    add_field => { "Hostname" => "%{One[5]}" }
}

```

To create a new field named "Hostname" and use the data in index 5 of the "One" field. However, I get this error in the logstash logs:

```auto
Exception caught while applying mutate filter {:exception=>"Invalid FieldReference: `One[5]`"}

```

According to this documentation, it should work:

 ![split](https://us1.discourse-cdn.com/elastic/original/3X/3/7/37faa5da4714ced2996cff673f0ef04281aa239f.png)

---

<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:** [January 28, 2021, 10:11pm UTC](https://discuss.elastic.co/t/split-field-and-add-new-fields/262571/2 "2021-01-28T22:11:47Z")

</div>

The documentation is out of date. The field reference should be

```
"%{[One][5]}"

```

References without square brackets was disallowed a few versions back.

---

<div class="post-metadata">

**Author:** ![jtillman2020](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jtillman2020](https://discuss.elastic.co/u/jtillman2020)\
**Post date:** [January 29, 2021, 1:36pm UTC](https://discuss.elastic.co/t/split-field-and-add-new-fields/262571/3 "2021-01-29T13:36:52Z")

</div>

That worked. Hopefully the documentation will get updated. One more thing. Once I split on the space:

```auto
<165>Original, Address=1.1.1.1, Jan, 28, 16:38:42, DeviceName, fpc3, DHCP, Packet, Drop:, Packet, src, ip/mac, 192.168.123.1/54:48:10:db:86:b6

```

Is there a way to retrieve just the three indexes at "DHCP, Packet, Drop" then combine them into one new field named "EventType"? So I would have "EventType: DHCP Packet Drop".

---

<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:** [January 29, 2021, 5:01pm UTC](https://discuss.elastic.co/t/split-field-and-add-new-fields/262571/4 "2021-01-29T17:01:51Z")

</div>

Use mutate+add\_field with multiple sprintf references

```
mutate {
    add_field => { "Hostname" => "%{[One][6]} %{[One][7]} %{[One][8]}" }
}
```

---

<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:** [February 26, 2021, 5:02pm UTC](https://discuss.elastic.co/t/split-field-and-add-new-fields/262571/5 "2021-02-26T17:02:13Z")

</div>

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