# Change the output of logstash if some criteria in filter fulfilled

**URL:** <https://discuss.elastic.co/t/change-the-output-of-logstash-if-some-criteria-in-filter-fulfilled/218987>\
**Category:** Logstash\
**Created:** [February 12, 2020, 1:26pm UTC](https://discuss.elastic.co/t/change-the-output-of-logstash-if-some-criteria-in-filter-fulfilled/218987 "2020-02-12T13:26:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arman\_Ajdani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arman_ajdani/32/47196_2.png) [@Arman\_Ajdani](https://discuss.elastic.co/u/Arman_Ajdani)\
**Post date:** [February 12, 2020, 1:26pm UTC](https://discuss.elastic.co/t/change-the-output-of-logstash-if-some-criteria-in-filter-fulfilled/218987/1 "2020-02-12T13:26:11Z")

</div>

Can I have two option on the output module on Logstash (suppose Kafka module) and check if some criteria happen in filter section I should send data to one of the output modules:

for example :

```
 filter {
if [1] in source:
       smth
if [2] in source:
     smth2
}

output { 
 if 1_in_source : 
     kafka {
    topic : 1
} 
if 2_in_source : 
    kafka {
   topic: 2
}
```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [February 12, 2020, 2:44pm UTC](https://discuss.elastic.co/t/change-the-output-of-logstash-if-some-criteria-in-filter-fulfilled/218987/2 "2020-02-12T14:44:23Z")

</div>

You can certainly use conditionals in the output section, although if the only difference in the output is the topic it might be better to use a single output and a sprintf reference to the topic.

---

<div class="post-metadata">

**Author:** ![Arman\_Ajdani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arman_ajdani/32/47196_2.png) [@Arman\_Ajdani](https://discuss.elastic.co/u/Arman_Ajdani)\
**Post date:** [February 12, 2020, 2:56pm UTC](https://discuss.elastic.co/t/change-the-output-of-logstash-if-some-criteria-in-filter-fulfilled/218987/4 "2020-02-12T14:56:47Z")

</div>

You mean I can check source in output section too? the only change is topic though , but I didn't understand the sprintf section.

---

<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:** [March 11, 2020, 2:56pm UTC](https://discuss.elastic.co/t/change-the-output-of-logstash-if-some-criteria-in-filter-fulfilled/218987/5 "2020-03-11T14:56:55Z")

</div>

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