gpt4 book ai didi

mysql - 使用 logstash 同步数据

转载 作者:太空宇宙 更新时间:2023-11-03 11:49:52 27 4
gpt4 key购买 nike

我正在尝试使用 logstash 将我在 MySql 服务器上的所有数据同步到我的 Elasticsearch 服务器。

我已经学习了 logstash.conf 的基础知识,这是我的文件:

input {
jdbc {
jdbc_connection_string => "jdbc:mysql://localhost/homestead"
jdbc_user => "homestead"
jdbc_password => "secret"
jdbc_driver_library => "/home/vagrant/Code/mysql-connector-java-5.1.38-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
statement => "SELECT * from volunteer"
}
jdbc {
jdbc_connection_string => "jdbc:mysql://localhost/homestead"
jdbc_user => "homestead"
jdbc_password => "secret"
jdbc_driver_library => "/home/vagrant/Code/mysql-connector-java-5.1.38-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
statement => "SELECT * from contact"
}

}
output {
elasticsearch {
document_id => "%{uid}"
hosts => "localhost"
}
}

我的意图是将每个表复制到一个类型中。我该如何指定?

编辑:“类型”而不是“索引” enter image description here

谢谢!

最佳答案

您可以做的只是在每个输入中添加一个字段(使用 add_field),表示您希望数据在其中建立索引的类型名称,然后使用该变量作为类型名称elasticsearch 输出。

input {
jdbc {
jdbc_connection_string => "jdbc:mysql://localhost/homestead"
jdbc_user => "homestead"
jdbc_password => "secret"
jdbc_driver_library => "/home/vagrant/Code/mysql-connector-java-5.1.38-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
statement => "SELECT * from volunteer"
add_field => {"type" => "volunteer"}
}
jdbc {
jdbc_connection_string => "jdbc:mysql://localhost/homestead"
jdbc_user => "homestead"
jdbc_password => "secret"
jdbc_driver_library => "/home/vagrant/Code/mysql-connector-java-5.1.38-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
statement => "SELECT * from contact"
add_field => {"type" => "contact"}
}
}
output {
elasticsearch {
hosts => ["localhost"]
index => "homestead"
document_type => "%{type}" <--- specify the index here
document_id => "%{uid}"
}
}

请注意,使用相同的索引来托管多个不同的映射类型可能会导致类型冲突。简而言之,两个不同类型中具有相同名称的两个不同字段必须始终具有相同的类型定义。了解更多信息 in this blog article

关于mysql - 使用 logstash 同步数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36172817/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com