# Splitting a data field into two

**URL:** <https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421>\
**Category:** Elasticsearch\
**Created:** [June 14, 2017, 4:26pm UTC](https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421 "2017-06-14T16:26:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_Farrell](https://avatars.discourse-cdn.com/v4/letter/w/8e8cbc/32.png) [@Will\_Farrell](https://discuss.elastic.co/u/Will_Farrell)\
**Post date:** [June 14, 2017, 4:26pm UTC](https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421/1 "2017-06-14T16:26:59Z")

</div>

Hello, i need to split a certain datafield I have into two separate fields. The field goes like this,

xx-xx0000:XXXXXxxx

where x's are letters and 0's are numbers.

I need to separate the field where the semicolon is but I haven't been able to figure out how to to do that yet. I've looked through the grok documentation but didn't find anything on separating based on a certain character.

Thanks.

---

<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:** [June 14, 2017, 4:44pm UTC](https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421/2 "2017-06-14T16:44:12Z")

</div>

Since you mention grok I guess this is really a logstash question. A filter with something like will do it.

`mutate { split => { "message" => ":" } }`

You probably want to replace message with whatever field you want to split, then maybe move the two array elements into their own fields.

---

<div class="post-metadata">

**Author:** ![Will\_Farrell](https://avatars.discourse-cdn.com/v4/letter/w/8e8cbc/32.png) [@Will\_Farrell](https://discuss.elastic.co/u/Will_Farrell)\
**Post date:** [June 14, 2017, 5:18pm UTC](https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421/3 "2017-06-14T17:18:02Z")

</div>

How would I send the two new items into two new fields?

Thanks

---

<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:** [June 14, 2017, 6:10pm UTC](https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421/4 "2017-06-14T18:10:50Z")

</div>

Use mutate's add\_field to reference the array entries that split returned.

```
mutate {
        add_field => {
                "firstPart" => "%{[message][0]}"
                "secondPart" => "%{[message][1]}"
        }
}

```

Again message would be replaced by the field name that you are splitting.

---

<div class="post-metadata">

**Author:** ![Will\_Farrell](https://avatars.discourse-cdn.com/v4/letter/w/8e8cbc/32.png) [@Will\_Farrell](https://discuss.elastic.co/u/Will_Farrell)\
**Post date:** [June 14, 2017, 6:12pm UTC](https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421/5 "2017-06-14T18:12:04Z")

</div>

Wow, great. Thank you very much for your help!

---

<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:** [June 14, 2017, 6:23pm UTC](https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421/6 "2017-06-14T18:23:48Z")

</div>

Fixed error in my response. Please read the updated version.

---

<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 12, 2017, 6:23pm UTC](https://discuss.elastic.co/t/splitting-a-data-field-into-two/89421/7 "2017-07-12T18:23:52Z")

</div>

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