logstash-6.2.3 配置同时读取多个本地文件到ES-6.2.3

        ELK stack采用6.2.3系列,配置conf文件读取多个本地json文件,导入到ES不同索引。

        具体思路:Input中写入多个file插件,每一个file有自己的type。Output中,采用 if条件语句,按照不同type来导入到不同的索引的type下面。因为一个索引只能有一个类型。

        PS:测试的时候,logstash仅仅第一次读取的file文件(json),如果第二次继续读取同样的文件,它是读取不了的,所以,要用另外的文件来测试。——因为logstash是根据文件更新时间来同步。

        另外,json文件一定要UTF-8编码,要不会报错:json语法错误。

        具体配置文件如下:

input { 
    stdin { } 
file {
    path => "D:\ELK\logstash_6.2.3\bin\conf\data_for_test\accounts.json"
    start_position => "beginning" 
    type => "accounts"
    }
file {
    path => "D:\ELK\logstash_6.2.3\bin\conf\data_for_test\logs.jsonl"
    start_position => "beginning" 
    type => "logs"
    }
file {
     path => "D:\ELK\logstash_6.2.3\bin\conf\data_for_test\shakespeare.json"
     start_position => "beginning" 
     type => "shakespeare"
     } 
}

filter {
    json {
    source => "message" // 以JSON格式解析
    target => "doc" // 解析到doc下面
    remove_field =>["message"] // 移除message
    } 
}

output {
    if[type] == "accounts"{
            elasticsearch {
                hosts  => "localhost:9200"
                index => "blog_001"
                document_type => "accounts"
        }
    }
    if[type] == "logs"{
            elasticsearch {
                hosts  => "localhost:9200"
                index => "blog_002"
                document_type => "logs"
        }
    }
    if[type] == "shakespeare"{
            elasticsearch {
                hosts  => "localhost:9200"
                index => "blog_003"
                document_type => "shakespeare"
        }
    }
stdout { 
    codec => rubydebug
    }
}

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值