# How to add fields to event from ruby plugin

**URL:** <https://discuss.elastic.co/t/how-to-add-fields-to-event-from-ruby-plugin/41289>\
**Category:** Logstash\
**Created:** [February 9, 2016, 3:26pm UTC](https://discuss.elastic.co/t/how-to-add-fields-to-event-from-ruby-plugin/41289 "2016-02-09T15:26:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjdepaul](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jjdepaul](https://discuss.elastic.co/u/jjdepaul)\
**Post date:** [February 9, 2016, 3:26pm UTC](https://discuss.elastic.co/t/how-to-add-fields-to-event-from-ruby-plugin/41289/1 "2016-02-09T15:26:12Z")

</div>

My config file accumulates data in the Class variables and does so until it's time to write out the 'aggregated' values into the Event. I don't know how to do that. Here is the code I have, which doesn't work. How do I add those fields into the Event?

```
            # When the Invoice Amount arrives, write out all the accumulated data to the Event
            if ([@metadata][amount] =~ /.+/) {
                ruby{
                    code => "@@InvoiceCurrency = event['@metadata']['currencyCode']
                             @@InvoiceAmount = event['@metadata']['amount']
                             
                             event = event + 
                             ' tslice=' + @@TimeStamp + 
                             ' senderID=' + @@SenderId + 
                             ' waterMark=' + @@WaterMark + 
                             ' accountId=' + @@AccountId + 
                             ' externalSource=' + @@ExternalSource + 
                             ' invoiceNumber=' + @@InvoiceNumber + 
                             ' invoiceDate=' + @@InvoiceDate + 
                             ' invoiceType=' + @@InvoiceType +
                             ' invoiceCurrency=' + @@InvoiceCurrency + 
                             ' invoiceAmount=' + @@InvoiceAmount "
                 }
            }
```

---

<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:** [February 9, 2016, 6:56pm UTC](https://discuss.elastic.co/t/how-to-add-fields-to-event-from-ruby-plugin/41289/2 "2016-02-09T18:56:53Z")

</div>

```auto
event['tslice'] = @@TimeStamp
event['senderID'] = @@SenderId
...

```

---

<div class="post-metadata">

**Author:** ![jjdepaul](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jjdepaul](https://discuss.elastic.co/u/jjdepaul)\
**Post date:** [February 9, 2016, 7:10pm UTC](https://discuss.elastic.co/t/how-to-add-fields-to-event-from-ruby-plugin/41289/3 "2016-02-09T19:10:12Z")

</div>

That simple, eh? I was thinking that only pertains to fields that already exist in the event.... thanks very much.

---

<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 6, 2017, 5:12am UTC](https://discuss.elastic.co/t/how-to-add-fields-to-event-from-ruby-plugin/41289/4 "2017-07-06T05:12:22Z")

</div>


