# Can I use conditional logic to filter log lines with filebeat?

**URL:** https://discuss.elastic.co/t/can-i-use-conditional-logic-to-filter-log-lines-with-filebeat/82791
**Category:** Beats
**Tags:** filebeat
**Created:** [April 18, 2017, 10:27pm UTC](https://discuss.elastic.co/t/can-i-use-conditional-logic-to-filter-log-lines-with-filebeat/82791 "2017-04-18T22:27:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![red888](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@red888](https://discuss.elastic.co/u/red888)
#### Post date: [April 18, 2017, 10:27pm UTC](https://discuss.elastic.co/t/can-i-use-conditional-logic-to-filter-log-lines-with-filebeat/82791/1 "2017-04-18T22:27:12Z")

</div>

I previously asked how I could send only a sample of my logs with filebeat: [Ship only a percentage of logs to logstash](https://discuss.elastic.co/t/ship-only-a-percentage-of-logs-to-logstash/77393)

Im filtering iis request logs and the volume is very high, i want a representative sample of all of those requests.

Right now I am doing this with nxlog and I am curious if this is possible with filebeat:  
Exec if (get\_var('count') == undef) set\_var('count',0);  
Exec set\_var('count', get\_var('count') + 1);  
Exec if (get\_var('count')%20 != 0) drop();

Im setting a counter for each log line and dropping it if it is not divisible by 20 (so effectively 5%).

How can I do this with filebeat?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [April 18, 2017, 11:05pm UTC](https://discuss.elastic.co/t/can-i-use-conditional-logic-to-filter-log-lines-with-filebeat/82791/2 "2017-04-18T23:05:53Z")

</div>

You'd have to send them to LS and then run a ruby filter with that logic.

---

<div class="post-metadata">

### Author: ![red888](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@red888](https://discuss.elastic.co/u/red888)
#### Post date: [April 19, 2017, 2:25pm UTC](https://discuss.elastic.co/t/can-i-use-conditional-logic-to-filter-log-lines-with-filebeat/82791/3 "2017-04-19T14:25:03Z")

</div>

Well logstash can actually just drop a percentage: [https://www.elastic.co/guide/en/logstash/current/plugins-filters-drop.html#plugins-filters-drop-percentage](https://www.elastic.co/guide/en/logstash/current/plugins-filters-drop.html#plugins-filters-drop-percentage)

But thats not my problem. I need to filter these logs on the endpoints side because of bandwidth concerns.

Sorry I already asked a similar question, but I thought if I included how I'm doing this with nxlog, someone might know an analogue for filebeat.

---

<div class="post-metadata">

### Author: ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)
#### Post date: [April 24, 2017, 7:35am UTC](https://discuss.elastic.co/t/can-i-use-conditional-logic-to-filter-log-lines-with-filebeat/82791/4 "2017-04-24T07:35:31Z")

</div>

There is currently no way to do this in Filebeat.

---

<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 22, 2017, 7:42am UTC](https://discuss.elastic.co/t/can-i-use-conditional-logic-to-filter-log-lines-with-filebeat/82791/5 "2017-05-22T07:42:56Z")

</div>

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