# Applying ruby code to several fields in an event?

**URL:** https://discuss.elastic.co/t/applying-ruby-code-to-several-fields-in-an-event/81541
**Category:** Logstash
**Created:** [April 6, 2017, 9:23pm UTC](https://discuss.elastic.co/t/applying-ruby-code-to-several-fields-in-an-event/81541 "2017-04-06T21:23:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Grigory\_Shamov](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@Grigory\_Shamov](https://discuss.elastic.co/u/Grigory_Shamov)
#### Post date: [April 6, 2017, 9:23pm UTC](https://discuss.elastic.co/t/applying-ruby-code-to-several-fields-in-an-event/81541/1 "2017-04-06T21:23:43Z")

</div>

Hi,

What would be the best way to applyc same ruby code to several fields? To grok something, then do (the same) math on the fields from the grok. Or to convert date/time to/from epoch. It is possible just to repeat the same code over and over (if [myfield] {ruby ...}) for each of the fields. But is that the best way?

---

<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: [April 7, 2017, 5:04am UTC](https://discuss.elastic.co/t/applying-ruby-code-to-several-fields-in-an-event/81541/2 "2017-04-07T05:04:38Z")

</div>

In the Ruby code just loop over the fields you want to process or, if you don't know which fields you might have, iterate over all fields.

---

<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: [May 5, 2017, 5:15am UTC](https://discuss.elastic.co/t/applying-ruby-code-to-several-fields-in-an-event/81541/3 "2017-05-05T05:15:06Z")

</div>

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