# Ruby Filter to Add Multiple Values to a Field

**URL:** <https://discuss.elastic.co/t/ruby-filter-to-add-multiple-values-to-a-field/186746>\
**Category:** Logstash\
**Created:** [June 20, 2019, 7:08pm UTC](https://discuss.elastic.co/t/ruby-filter-to-add-multiple-values-to-a-field/186746 "2019-06-20T19:08:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cappy](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@cappy](https://discuss.elastic.co/u/cappy)\
**Post date:** [June 20, 2019, 7:08pm UTC](https://discuss.elastic.co/t/ruby-filter-to-add-multiple-values-to-a-field/186746/1 "2019-06-20T19:08:21Z")

</div>

Hello,

Due to the fact that a field is getting interpreted as a single string and attempted to be indexed into Elasticsearch as type `ip` (and failing due to mapping, rightfully so), I am looking to take values separated by commas, then add them to a mutli-valued field.

For example, I have a field `destination_ip_orig` with a value of `192.168.1.1,192.168.1.2` that has been pulled using the `csv` filter.

I would like to make that in to a mutli-valued field called `destination_ip` with the values of `192.168.1.1` and `192.168.1.2`.

Because the number of values can fluctuate from `1 to n`, I am using Ruby to iterate through the values, and add them to the multi-valued field.

I have tried:

```
ruby {
    code => "
        inputs = event.get('destination_ip_orig').split(',')
        for input in inputs
            event.set('destination_ip', event.get('destination_ip') + input )
        end
    "
}

```

...but I receive an error with regard to array and string conversion, etc.

I have also tried `input` as `[input]`, and `['input']`, but once I do use it that way, it just seems to concatenate the values, instead of adding them as elements to the array.

I think I have been looking at it too long. Is it something simple, or am I over complicating it?

Any help would be appreciated!

---

<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 20, 2019, 8:01pm UTC](https://discuss.elastic.co/t/ruby-filter-to-add-multiple-values-to-a-field/186746/2 "2019-06-20T20:01:35Z")

</div>

mutate will do this for you

```
mutate { split => { "ip" => "," } }
```

---

<div class="post-metadata">

**Author:** ![cappy](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@cappy](https://discuss.elastic.co/u/cappy)\
**Post date:** [June 20, 2019, 9:13pm UTC](https://discuss.elastic.co/t/ruby-filter-to-add-multiple-values-to-a-field/186746/3 "2019-06-20T21:13:33Z")

</div>

That did the trick! Can't believe I overlooked that! Thanks!

---

<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 18, 2019, 9:13pm UTC](https://discuss.elastic.co/t/ruby-filter-to-add-multiple-values-to-a-field/186746/4 "2019-07-18T21:13:50Z")

</div>

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