# Single key (field) with multiple values to multiple key (fields) with single fields convertion

**URL:** https://discuss.elastic.co/t/single-key-field-with-multiple-values-to-multiple-key-fields-with-single-fields-convertion/204090
**Category:** Logstash
**Created:** [October 17, 2019, 3:25pm UTC](https://discuss.elastic.co/t/single-key-field-with-multiple-values-to-multiple-key-fields-with-single-fields-convertion/204090 "2019-10-17T15:25:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Andres\_Man](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andres_man/32/52195_2.png) [@Andres\_Man](https://discuss.elastic.co/u/Andres_Man)
#### Post date: [October 17, 2019, 3:25pm UTC](https://discuss.elastic.co/t/single-key-field-with-multiple-values-to-multiple-key-fields-with-single-fields-convertion/204090/1 "2019-10-17T15:25:03Z")

</div>

I need to split a log into multiple fields however the log has the same field name for multiple values and when I use the fiedl\_split option of kv it will put all the the fields with the same key in the same field. How can I put the values into separate fields with distinct names.

The desire output should be:  
pin=12345-0 d=123 [A\_foo=nice@bar.com](mailto:A_foo=nice@bar.com) B\_foo=bobo C\_foo=12345.

However what I'm getting right now is:  
pin=12345~0 d=123 foo= [nice@bar.com](mailto:nice@bar.com), bobo, 1234

[//pin=12345~0&d=123&foo=nice@bar.com](https://pin=12345~0&d=123&foo=nice@bar.com)&foo=bobo&foo=12345 //

// filter { //  
// kv { //  
// field\_split =\> "&?" //  
// } //  
// } //

---

<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: [October 17, 2019, 3:49pm UTC](https://discuss.elastic.co/t/single-key-field-with-multiple-values-to-multiple-key-fields-with-single-fields-convertion/204090/2 "2019-10-17T15:49:25Z")

</div>

You could do that using a ruby filter

```
    kv { field_split => "&" }
    ruby {
        code => '
            foo = event.get("foo")
            foo.each_index { |x|
                event.set("foo-#{x}", foo[x])
            }
        '
    }
```

---

<div class="post-metadata">

### Author: ![Andres\_Man](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andres_man/32/52195_2.png) [@Andres\_Man](https://discuss.elastic.co/u/Andres_Man)
#### Post date: [October 17, 2019, 3:50pm UTC](https://discuss.elastic.co/t/single-key-field-with-multiple-values-to-multiple-key-fields-with-single-fields-convertion/204090/3 "2019-10-17T15:50:41Z")

</div>

@Badger Thanks, that did the trick.

---

<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: [November 14, 2019, 3:50pm UTC](https://discuss.elastic.co/t/single-key-field-with-multiple-values-to-multiple-key-fields-with-single-fields-convertion/204090/4 "2019-11-14T15:50:45Z")

</div>

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