# Adding fields based on match

**URL:** <https://discuss.elastic.co/t/adding-fields-based-on-match/310094>\
**Category:** Logstash\
**Created:** [July 20, 2022, 6:53am UTC](https://discuss.elastic.co/t/adding-fields-based-on-match/310094 "2022-07-20T06:53:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rusty\_cole](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@rusty\_cole](https://discuss.elastic.co/u/rusty_cole)\
**Post date:** [July 20, 2022, 6:53am UTC](https://discuss.elastic.co/t/adding-fields-based-on-match/310094/1 "2022-07-20T06:53:04Z")

</div>

Hi All,  
I have the following scenario:  
1 index containing json fields.  
I need to match Event1\_fieldA to Event2\_fieldB.  
If there is a match, add additional existing field from Event2 to Event1.  
How would I achieve this?  
Do I have to use logstash?  
I tried playing with the aggregate filter but got nothing useful.  
This is what I have so far:

```auto
if [somefield] == "somevalue" {
aggregate {
     task_id => "%{[fieldA][fieldB]}"
   code => "
     map['Test'] = event.get('additional existing field in Event2')
   "
   map_action => "create"
   end_of_task => true
   timeout => 3

 }    
 }

```

Any help would be greatly appreciated.

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:** [August 17, 2022, 6:53am UTC](https://discuss.elastic.co/t/adding-fields-based-on-match/310094/2 "2022-08-17T06:53:55Z")

</div>

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