# Logstash create value based on duplicate field

**URL:** <https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852>\
**Category:** Logstash\
**Created:** [October 3, 2020, 12:33am UTC](https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852 "2020-10-03T00:33:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbwolf](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bbwolf](https://discuss.elastic.co/u/bbwolf)\
**Post date:** [October 3, 2020, 12:33am UTC](https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852/1 "2020-10-03T00:33:48Z")

</div>

Hello,  
I wan't know if it's possible to get duplicate value un field and create another field based on that value.  
Supposed I have logs:  
Field1, Field2, Field3  
A,B, C  
A,D, E  
B, E, T  
B, R, H  
S, V, X  
What I wan't to have is :  
Field1, Field2, Field3, Field4  
A,B, C, 1  
A,D, E, 0 (because we know A)  
B, E, T, 1  
B, R, H, 0  
S, V, X, 1

Thank you

---

<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 3, 2020, 1:19pm UTC](https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852/2 "2020-10-03T13:19:42Z")

</div>

You could probably do that with an aggregate or ruby filter. Use A/B etc as the task\_id. Check if the map already contains something for the task\_id. If so, set the field to 1, otherwise 0. Then add a value to the map. You would never purge entries from the map, so this would leak memory.

---

<div class="post-metadata">

**Author:** ![bbwolf](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bbwolf](https://discuss.elastic.co/u/bbwolf)\
**Post date:** [October 3, 2020, 7:47pm UTC](https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852/3 "2020-10-03T19:47:27Z")

</div>

Thank you for the response.  
But the problem is I have many value on Field1 and not just A or B.  
In the given example, we have three different value but in real log I have at least 4000 distinct value.

---

<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 3, 2020, 8:47pm UTC](https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852/4 "2020-10-03T20:47:45Z")

</div>

I do not see why having thousand of possible values makes a difference. If it were millions of values I would be concerned, but thousands should be OK.

---

<div class="post-metadata">

**Author:** ![bbwolf](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bbwolf](https://discuss.elastic.co/u/bbwolf)\
**Post date:** [October 4, 2020, 6:48pm UTC](https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852/5 "2020-10-04T18:48:57Z")

</div>

Thank you, gonna check this!

---

<div class="post-metadata">

**Author:** ![bbwolf](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bbwolf](https://discuss.elastic.co/u/bbwolf)\
**Post date:** [October 8, 2020, 10:19am UTC](https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852/6 "2020-10-08T10:19:42Z")

</div>

Hello @Badger,  
It is a good solution and if I want to have the number of fields as count like :

```auto
Field1, field2, field3, field4, count_event
 A,B, C, 1,2
A,D, E, 0,2
B, E, T, 1,2
B, R, H, 0,2
S, V, X, 1,1

```

Regards

---

<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 5, 2020, 10:19am UTC](https://discuss.elastic.co/t/logstash-create-value-based-on-duplicate-field/250852/7 "2020-11-05T10:19:43Z")

</div>

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