zxq209  
                
                  
                    March 15, 2018, 11:56am
                   
                  1 
               
             
            
              I'm using logstash-2.4.1 and elasticsearch-2.4.6.
input {
            file {
     type => "toll"
    path => ["/path/to/file4/*.log"]
    ignore_older => 0
    start_position => beginning
    sincedb_path => "/path/to/file4/sincedb.txt"
    codec => json {
    charset => ["UTF-8"]
 }
}
}
    output{
     elasticsearch {        
    			hosts => [ "192.168.4.56:9200","192.168.15.145:9200","192.168.15.41:9200" ]        
    			index => "data_%{application}"    }
    }
But when I use "if" condition to chose the different output,logstash can't write anything into EL.
 input {
            file {
                type => "toll"
                path => ["/path/to/file4/*.log"]
                ignore_older => 0
                start_position => beginning
                sincedb_path => "/path/to/file4/sincedb.txt"
                codec => json {
              charset => ["UTF-8"]
            }
             }
            }
    output{
    if [type] == "toll"{
     elasticsearch {        
    			hosts => [ "192.168.4.56:9200","192.168.15.145:9200","192.168.15.41:9200" ]        
    			index => "data_%{application}"    }
      }
    }
Are there any problems in my config file,or Is the version issue?
             
            
              
            
           
          
            
            
              Use a stdout { codec => rubydebug } output to dump the raw event. Does the type field really  contain "toll"? Are you getting any events at all?
             
            
              1 Like 
            
            
           
          
            
              
                zxq209  
              
                  
                    March 16, 2018,  1:42am
                   
                  3 
               
             
            
              thank you reply.
I output the data,like this:@version " => "1",@timestamp " => "2018-03-16T01:11:16.612Z",
So,I changed the config file like this:
But it still doesn't work,no index is created.
I thought the "type" is  from "file" that I have set  not from the json field.
I deleted the sincedb and remove the "if condition",the index was created and the data flowed into EL.
Hope to get your help,thanks.
             
            
              
            
           
          
            
              
                zxq209  
              
                  
                    March 16, 2018,  2:05am
                   
                  4 
               
             
            
              @magnusbaeck  thank you very much.
I change the config,like this:
   file {
        type => "response"
        path => ["/path/to/file4/*.log"]
        ignore_older => 0
        start_position => beginning
        sincedb_path => "/path/to/file4/sincedb.txt"
        codec => json {
      charset => ["UTF-8"]
  }
  }
}
#output{stdout { codec => rubydebug }}
output{
    if [type] == "response"{
     elasticsearch {
                        hosts => ["192.168.15.145:9200"]
                        index => "data_%{application}"
                                }
      }
        }
It works!
             
            
              
            
           
          
            
            
              
I thought the "type" is from "file" that I have set not from the json field.
 
Apparently the file input doesn't overwrite the type field read from the file, so if it's present in the file it'll get used and otherwise the file input's type option will prevail.
             
            
              
            
           
          
            
              
                system  
              
                  
                    April 13, 2018,  6:58am
                   
                  6 
               
             
            
              This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.