Logstash-5.0同步.json文件到ElasticSearch-5.0配置文件


logstash/conf/input-file.conf內容如下:

input {
    file {
        #監聽文件的路徑。
        path => ["E:/data_json/*.json"]
        #排除不想監聽的文件
        #exclude => "1.log"
        
        #添加自定義的字段
        #add_field => {"test"=>"test"}
        #增加標簽
        #tags => "tag1"

        #設置新事件的標志
        #delimiter => "\n"

        #設置多長時間掃描目錄,發現新文件
        discover_interval => 1
        #設置多長時間檢測文件是否修改
        stat_interval => 1

        #監聽文件的起始位置,默認是end
        start_position => beginning

        #在logstash-5.0中,json_lines插件貌似不起作用?
        #codec => json_lines {charset => ["UTF-8"]}
        
        #監聽文件讀取信息記錄的位置
        #sincedb_path => "E:/logstash-5.0.0/sincedb_path.txt"
        #設置多長時間會寫入讀取的位置信息
        #sincedb_write_interval => 15
       
    }
}

filter {
  json {
    #add_field => ... # default: {}
    #add_tag => ... # array (optional), default: []
    #remove_field => ... # array (optional), default: []
    #remove_tag => ... # array (optional), default: []
    source => "name"
    target => "user_name"
  }
}

output {
  elasticsearch {
    #ESIP地址與端口
    hosts => "localhost:9200"
    #ES索引名稱(自己定義的)
    index => "m8"
    #自增ID編號
    #document_id => "%{id}"
  }
  stdout {
    #以JSON格式輸出
    #codec => json_lines
  }
}

啟動logstash命令:

bin/logstash -f ../config/input-file.conf

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM