# Write ruby filter method in class

**URL:** <https://discuss.elastic.co/t/write-ruby-filter-method-in-class/113873>\
**Category:** Logstash\
**Created:** [January 3, 2018, 4:53am UTC](https://discuss.elastic.co/t/write-ruby-filter-method-in-class/113873 "2018-01-03T04:53:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradeep\_reddy](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@pradeep\_reddy](https://discuss.elastic.co/u/pradeep_reddy)\
**Post date:** [January 3, 2018, 4:53am UTC](https://discuss.elastic.co/t/write-ruby-filter-method-in-class/113873/1 "2018-01-03T04:53:04Z")

</div>

Hi,

I have to map the keys in event to other fields which comes from external configuration .

my event:

```
     "id" => 10,
"updated_on" => 2018-01-03T03:17:56.000Z,
      "name" => "ggd",
      "type" => "mysql_read"

```

for one of the type i wanted to replace id with id\_new for other type i wanted to replace id with id\_new\_2

how can achieve this ? is there any already existing filter plugin which supports this

-- what i tried

created a mapping class whcih maps to fileld based on type all the mappings are instances variables .

class Mapping

@@mysql\_read\_id=id\_new  
@@mysql\_read\_name=first\_name

end

is it possible to read this class level variables in my ruby filter method .

please help me

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [January 4, 2018, 3:07pm UTC](https://discuss.elastic.co/t/write-ruby-filter-method-in-class/113873/2 "2018-01-04T15:07:19Z")

</div>

You will need to explain a bit more of your general problem with actual sample data.

I suspect that you can use the translate filter.

Very few people need to resort to using class variables in a ruby filter.

---

<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:** [February 1, 2018, 3:07pm UTC](https://discuss.elastic.co/t/write-ruby-filter-method-in-class/113873/3 "2018-02-01T15:07:20Z")

</div>

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