为了同步 elasticsearch 和 mongodb,我已经配置了 logstash。
这是我正常工作的配置:
input {
mongodb {
uri => '<my_mongo_db_uri>'
placeholder_db_dir => '/opt/logstash-mongodb/'
placeholder_db_name => '<my_placeholeder>.db'
collection => '<my_mongo_db_collection>'
batch_size => 5000
}
}
filter {
mutate {
remove_field => ["_id"]
}
}
output {
stdout {
codec => rubydebug
}
elasticsearch {
action => "index"
index => "<my_index>"
hosts => ["http://<my_elasticsearch_ip>:9200"]
}
}
现在我会更新它,以便在 elasticsearch 中自动传播任何 mongo 文档修改。
有人能给我打电话吗?
您可以在logstash => output => elasticsearch
中使用
document_id来更新文档部分。 这是一个例子:
input {
mongodb {
uri => '<my_mongo_db_uri>'
placeholder_db_dir => '/opt/logstash-mongodb/'
placeholder_db_name => '<my_placeholeder>.db'
collection => '<my_mongo_db_collection>'
batch_size => 5000
}
}
filter {
mutate {
rename => {"_id" => "id"}
}
}
output {
elasticsearch {
index => "<my_index>"
hosts => ["http://<my_elasticsearch_ip>:9200"]
document_id => "%{id}"
}
}