# Logstash multiple ruby filter

**URL:** <https://discuss.elastic.co/t/logstash-multiple-ruby-filter/237758>\
**Category:** Logstash\
**Created:** [June 19, 2020, 7:58am UTC](https://discuss.elastic.co/t/logstash-multiple-ruby-filter/237758 "2020-06-19T07:58:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohoroyoi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ohoroyoi/32/46820_2.png) [@ohoroyoi](https://discuss.elastic.co/u/ohoroyoi)\
**Post date:** [June 19, 2020, 7:58am UTC](https://discuss.elastic.co/t/logstash-multiple-ruby-filter/237758/1 "2020-06-19T07:58:00Z")

</div>

I'm bringing table A and B from postgres. I want to apply the ruby filter in different forms. How should I set it up?

```auto
input {
     jdbc { tags => table A }
     jdbc { tags => table B }
}

filter {
    ruby {
     code=> "require 'json'
                  ...
"
   }

This ruby filter only says'event'. How does the ruby filter know this? Is it a filter on table A or a filter on table B?
}

```

---

<div class="post-metadata">

**Author:** ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)\
**Post date:** [June 20, 2020, 2:11am UTC](https://discuss.elastic.co/t/logstash-multiple-ruby-filter/237758/2 "2020-06-20T02:11:45Z")

</div>

you can apply different tags for different input, then use conditionals in your filter

---

<div class="post-metadata">

**Author:** ![ohoroyoi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ohoroyoi/32/46820_2.png) [@ohoroyoi](https://discuss.elastic.co/u/ohoroyoi)\
**Post date:** [June 22, 2020, 2:23am UTC](https://discuss.elastic.co/t/logstash-multiple-ruby-filter/237758/3 "2020-06-22T02:23:11Z")

</div>

@ptamba hello. as you can see, I already applied tags in each inputs. What I asked is how to apply the filter to each tag, so if you know about this, please explain it with code. thank you

---

<div class="post-metadata">

**Author:** ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)\
**Post date:** [June 22, 2020, 4:28am UTC](https://discuss.elastic.co/t/logstash-multiple-ruby-filter/237758/4 "2020-06-22T04:28:22Z")

</div>

```
input { 
   jdbc { 
    #jdbc settings for tableA
     tags => ["tableA"] 
  }
  jdbc 
  #jdbc setting for tableB
 {
    tags => ["tableB"]
 }
}

filter { 
  if "tableA" in [tags] {
   ruby { 
    #ruby codes for A here 
   }
 }
 else if "tableB" in [tags] {
   ruby {
   # ruby codes for tableB here 
  }
}

```

more in the [docs](https://www.elastic.co/guide/en/logstash/current/config-examples.html#using-conditionals) about conditionals

---

<div class="post-metadata">

**Author:** ![ohoroyoi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ohoroyoi/32/46820_2.png) [@ohoroyoi](https://discuss.elastic.co/u/ohoroyoi)\
**Post date:** [June 22, 2020, 5:15am UTC](https://discuss.elastic.co/t/logstash-multiple-ruby-filter/237758/5 "2020-06-22T05:15:17Z")

</div>

Thanks. It helped a lot. When I only looked at the document, I wasn't really sure if I could use the filter under these conditions.

May I ask you one more? I want to clone "tableA" based on your example and divide it into "tableA-1" and "tableA-2", and output three tablesB to the index of elasticsearch respectively. TableA already has a type, is it possible to clone it and give it another type? I have to divide as "tableA-1", "tableA-2", "tableB"

---

<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 20, 2020, 5:15am UTC](https://discuss.elastic.co/t/logstash-multiple-ruby-filter/237758/6 "2020-07-20T05:15:22Z")

</div>

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