Q:

How to filter java logs using logstash?

I need to filter only java fatal logs and put that logs into elasticsearch index using logstash pipeline.
I put logs to an elasticsearch index. but it has all the logs(ex- info,debug).
Sample log entry:
2019-05-06 14:37:23 DEBUG Scheduler : Starting Scheduler... 2019-05-06 14:37:24 INFO Scheduler : Quartz scheduler started

A:

I guess your log entries could be something like this.
Ex:
2019-04-23 10:12:10 INFO - 12345 - SQL - sqlQuery1 - 12
2019-04-23 10:12:10 FATAL - 12345 - SQL - sqlQuery2 - 34
2019-04-23 10:12:10 INFO - 12345 - TASK_END - end

For this input, Logstash filter could be something like this;
filter {
   grok {
     match => [ "message" => "%{NOTSPACE:datetime} - %{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
   }

   if [loglevel] =~ "FATAL" {
     drop { }
   }
}

output {
    elasticsearch {
          hosts => ["elasticsearch:9200"]
          index => "indexfatal-%{+YYYY.MM.dd}"
    }
}

I'm mapping the input entries using grok plugin and then check and drop non-FATAL entries to exclude them from the index. 
This might require slight nudge to work with your logs.

