logstash同步mongodb数据到elasticsearch

时间:2023-03-09 07:46:13
logstash同步mongodb数据到elasticsearch

一、安装logstash

二、安装mongodb插件

cd D:\Software\ELK5.5.0\logstash-5.5.0\bin

logstash-plugin install logstash-output-mongodb

logstash-plugin install logstash-input-mongodb

要先装output再装input,不然会报mongo版本冲突

D:\Software\ELK5.5.0\logstash-5.5.0\bin\mongo\productinfo.conf配置文件如下:

input {
mongodb {
uri => "mongodb://username:password@192.168.1.111:7001/Mall_search?ssl=false"
placeholder_db_dir => "D:\opt\logstash-mongodb"
placeholder_db_name => "eb_search_mongo.db"
collection => "ProductInfo_ObjectId"
batch_size =>
type => "product"
}
}
filter {
mutate {
remove_field => [ "_id" ]
}
} output {
elasticsearch {
hosts => ["192.168.1.58:9200"]
index => "sync_mongo_productinfo_201801166666677"
document_id => "%{ProductID}"
}
stdout { codec => rubydebug }
}

启动命令:

cd D:\Software\ELK5.5.0\logstash-5.5.0\bin

.\logstash.bat -f  .\mongo\productinfo.conf