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),如果第二次继续读取同样的文件,它是读取不了的,所以,要用另外的文件来测试。

另外,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
}
}

猜你喜欢

转载自blog.csdn.net/aganliang/article/details/80027710