# Tail once - route output based on filter

**URL:** <https://discuss.elastic.co/t/tail-once-route-output-based-on-filter/130243>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [May 2, 2018, 11:34am UTC](https://discuss.elastic.co/t/tail-once-route-output-based-on-filter/130243 "2018-05-02T11:34:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomer\_Yakir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomer_yakir/32/30679_2.png) [@Tomer\_Yakir](https://discuss.elastic.co/u/Tomer_Yakir)\
**Post date:** [May 2, 2018, 11:34am UTC](https://discuss.elastic.co/t/tail-once-route-output-based-on-filter/130243/1 "2018-05-02T11:34:56Z")

</div>

Hi,

I have the following use case:  
Using Filebeat to tail a single log file. Based on the type of log entry detected I need to route the data to a different custom processor.  
For example:

- Lines that start with A would be stored as is
- Lines that start with B would be pre-aggregated (count the number of lines of this type), then stored somewhere else

Note that I'm using Filebeat as a "go" library.  
Currently what I'm doing is define a single prospector with multiple entries on "include\_lines", then evaluate conditions on the Outlet to determine how to route the event.  
Ideally I would be able to evaluate once instead of twice. Is that possible?

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [May 2, 2018, 3:55pm UTC](https://discuss.elastic.co/t/tail-once-route-output-based-on-filter/130243/2 "2018-05-02T15:55:45Z")

</div>

You want to route events to different outputs (logstash, elasticsearch) or do you need some way of filtering/processing only? The later can be done in configuration only. Processors support conditions (regex, string match, ...).

---

<div class="post-metadata">

**Author:** ![Tomer\_Yakir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomer_yakir/32/30679_2.png) [@Tomer\_Yakir](https://discuss.elastic.co/u/Tomer_Yakir)\
**Post date:** [May 3, 2018, 7:58am UTC](https://discuss.elastic.co/t/tail-once-route-output-based-on-filter/130243/3 "2018-05-03T07:58:41Z")

</div>

Hi Steffen,

So, I believe it's a combination of both.  
For a given log entry, I'd like to do something like (pseudo-code):

```
if line.contains("A") {
     dict = custom_aggregate(line, dict)
} else if line.contains("B") {
    store_in_custom_system_a(line)
} else if line.contains("C") {
     store_in_custom_system_b(line)
}
```

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [May 3, 2018, 11:58am UTC](https://discuss.elastic.co/t/tail-once-route-output-based-on-filter/130243/4 "2018-05-03T11:58:03Z")

</div>

Some filtering can be done in filebeat using processors with conditionals (See [docs with examples](https://www.elastic.co/guide/en/beats/filebeat/current/filtering-and-enhancing-data.html#filtering-and-enhancing-data) and list of available processors).

Filebeat does not support event routing. The closes to event routing is a configurable index name for the Elasticsearch output (or kafka topic). If you need more routing capabilities based on actual contents, you would have to use Logstash.

---

<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 31, 2018, 11:58am UTC](https://discuss.elastic.co/t/tail-once-route-output-based-on-filter/130243/5 "2018-05-31T11:58:03Z")

</div>

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