使用 logstash 同步数据
using logstash to sync data
我正在尝试使用 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"
}
}
我的意图是将每个 table 复制到一个类型中。我该如何指定?
编辑:"type" 而不是 "index"
谢谢!
你可以做的只是在每个输入中添加一个字段(使用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
我正在尝试使用 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"
}
}
我的意图是将每个 table 复制到一个类型中。我该如何指定?
编辑:"type" 而不是 "index"
谢谢!
你可以做的只是在每个输入中添加一个字段(使用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