当 mongodb 数据更新时,Logstash 不会更新数据

问题描述 投票:0回答:1

为了同步 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 文档修改。

有人能给我打电话吗?

mongodb elasticsearch logstash logstash-configuration
1个回答
0
投票

您可以在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}"
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.