# How to deal with duplicate fields in a message

**URL:** <https://discuss.elastic.co/t/how-to-deal-with-duplicate-fields-in-a-message/92790>\
**Category:** Logstash\
**Created:** [July 12, 2017, 9:50am UTC](https://discuss.elastic.co/t/how-to-deal-with-duplicate-fields-in-a-message/92790 "2017-07-12T09:50:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sentinel](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@sentinel](https://discuss.elastic.co/u/sentinel)\
**Post date:** [July 12, 2017, 9:50am UTC](https://discuss.elastic.co/t/how-to-deal-with-duplicate-fields-in-a-message/92790/1 "2017-07-12T09:50:40Z")

</div>

Hi Guys, for swap transactions there are usually 2 legs. Unfortunately the application spews everything out and doesn't give the legs any distinct name so I end up with the value for both legs of the transaction duplicated. here's an example message:

[requestId=R20170704l, requestType=Credit Check Request, timeStamp=2017-07-04T12:50:59.892Z, deals { Deal [ dealId=R20170704l, counterPartyId=12345, memberBank=YOBANK, legs { Leg [ legId=R20170704l.1.1, product=FX\_FORWARD, symbol=USDHUF, baseCcy=USD, termCcy=HUF, dealCcy=HUF, dealtAmount=4500000000, contraCcy=USD, contraAmount=16549289.30, valueDate=20170705, spotDate=20170706]Leg [legId=R20170704l.1.2, product=FX\_SPOT, symbol=USDHUF, baseCcy=USD, termCcy=HUF, dealCcy=HUF, dealtAmount=4500000000, contraCcy=USD, contraAmount=16549289.30, valueDate=20170706, spotDate=20170706] } ] } ]]

So I end up with

![](https://us1.discourse-cdn.com/elastic/original/3X/2/d/2d9525b28ef62efd0dc47c52e58d90f6a0415b94.png)

How do I filter this out so I can name both legs separately and allow their corresponding values to match up?

---

<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:** [July 12, 2017, 3:08pm UTC](https://discuss.elastic.co/t/how-to-deal-with-duplicate-fields-in-a-message/92790/2 "2017-07-12T15:08:18Z")

</div>

Are you using a kv filter for parsing this? If yes, wouldn't `allow_duplicate_values => false` help?

Apart from that I don't think there's any standard filter to help you here, but a simple ruby filter that rewrites a field if it's an array with two identical values.

---

<div class="post-metadata">

**Author:** ![sentinel](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@sentinel](https://discuss.elastic.co/u/sentinel)\
**Post date:** [July 13, 2017, 4:39pm UTC](https://discuss.elastic.co/t/how-to-deal-with-duplicate-fields-in-a-message/92790/3 "2017-07-13T16:39:15Z")

</div>

Thanks Magnus that really helped

---

<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:** [August 10, 2017, 4:39pm UTC](https://discuss.elastic.co/t/how-to-deal-with-duplicate-fields-in-a-message/92790/4 "2017-08-10T16:39:28Z")

</div>

Closed on August 10, 2017, 4:39pm UTC

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