# Disallow duplicate key to be added on kv

**URL:** <https://discuss.elastic.co/t/disallow-duplicate-key-to-be-added-on-kv/86323>\
**Category:** Logstash\
**Created:** [May 18, 2017, 6:49pm UTC](https://discuss.elastic.co/t/disallow-duplicate-key-to-be-added-on-kv/86323 "2017-05-18T18:49:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Cross](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_cross/32/104500_2.png) [@Justin\_Cross](https://discuss.elastic.co/u/Justin_Cross)\
**Post date:** [May 18, 2017, 6:49pm UTC](https://discuss.elastic.co/t/disallow-duplicate-key-to-be-added-on-kv/86323/1 "2017-05-18T18:49:31Z")

</div>

I need to stop logstash from adding to ReceiverInfo more than once.

msg\_attributes = ReceiverInfo=111111111,ReceiverInfo=22222222,ReceiverInfo=3333333333

It should add the first key/value and then no more. What I end up with is an array of 3 values for the ReceiverInfo field. At the end I should have one field called ReceiverInfo that contains 111111111.

```
kv {
    source => "msg_attributes"
    field_split => ","
}

```

Please help, thanks.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [May 29, 2017, 8:15pm UTC](https://discuss.elastic.co/t/disallow-duplicate-key-to-be-added-on-kv/86323/2 "2017-05-29T20:15:52Z")

</div>

There doesn't appear to exist anything builtin to do this, but it's a simple operation with a ruby filter. A code snippet like this should work:

```
event.set('ReceiverInfo', event.get('ReceiverInfo')[0])

```

This assumes that the `ReceiverInfo` field exists and is an array with at least one element.

---

<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:** [June 26, 2017, 8:15pm UTC](https://discuss.elastic.co/t/disallow-duplicate-key-to-be-added-on-kv/86323/3 "2017-06-26T20:15:59Z")

</div>

Closed on June 26, 2017, 8:15pm UTC

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