# Ingest only ERROR and warning logs to elastic search

**URL:** <https://discuss.elastic.co/t/ingest-only-error-and-warning-logs-to-elastic-search/319634>\
**Category:** Logstash\
**Created:** [November 23, 2022, 9:07am UTC](https://discuss.elastic.co/t/ingest-only-error-and-warning-logs-to-elastic-search/319634 "2022-11-23T09:07:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul\_sirugudi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_sirugudi/32/94019_2.png) [@rahul\_sirugudi](https://discuss.elastic.co/u/rahul_sirugudi)\
**Post date:** [November 23, 2022, 9:07am UTC](https://discuss.elastic.co/t/ingest-only-error-and-warning-logs-to-elastic-search/319634/1 "2022-11-23T09:07:21Z")

</div>

Hi I am trying to ingest only ERROR and warning logs to Elasticsearch. Currently filebeat is shipping logs to log stash, i am using grok pattern.

```auto
grok {
match => { "message" => "%{IPV4:ip} - \[%{TIMESTAMP_ISO8601:timestamp}\] - %{GREEDYDATA:message} - %{GREEDYDATA:pool} - %{LOGLEVEL:log-level} : %{GREEDYDATA:error-message}" }
}
output {
if [fields][type] == "application_logs"
{
    elasticsearch {
    hosts => ["ip:9200"]
   user => "elastic"
   password => "password"
   index => "application-logs"
   }
 if "ERROR" in [log-level]
{
   stdout { codec => rubydebug }
  }

}
}

```

This above pattern is showing all logs including INFO. What can be done here?

---

<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:** [November 23, 2022, 8:06pm UTC](https://discuss.elastic.co/t/ingest-only-error-and-warning-logs-to-elastic-search/319634/2 "2022-11-23T20:06:13Z")

</div>

Try wrapping your elasticsearch output in something like

```
if [log-level] in ["ERROR", "WARN"] {
    ...
}

```

---

<div class="post-metadata">

**Author:** ![rahul\_sirugudi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_sirugudi/32/94019_2.png) [@rahul\_sirugudi](https://discuss.elastic.co/u/rahul_sirugudi)\
**Post date:** [November 24, 2022, 4:55am UTC](https://discuss.elastic.co/t/ingest-only-error-and-warning-logs-to-elastic-search/319634/3 "2022-11-24T04:55:28Z")

</div>

Thanks Tried that, it worked i have to make few changes to file.

```auto
grok {
match => { "message" => "%{IPV4:ip} - \[%{TIMESTAMP_ISO8601:timestamp}\] - %{GREEDYDATA:message} - %{GREEDYDATA:pool} - %{LOGLEVEL:log-level} : %{GREEDYDATA:error-message}" }
}
output {
if [fields][type] == "application_logs"
{
 if [log-level] in ["ERROR", "WARN"]
{
   stdout { codec => rubydebug }
  }
    elasticsearch {
    hosts => ["ip:9200"]
   user => "elastic"
   password => "password"
   index => "application-logs"
   }

}
}
}

```

---

<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:** [December 22, 2022, 4:56am UTC](https://discuss.elastic.co/t/ingest-only-error-and-warning-logs-to-elastic-search/319634/4 "2022-12-22T04:56:16Z")

</div>

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