简体   繁体   English

使用logstash同步数据

[英]using logstash to sync data

I'm trying to use logstash to sync all my data on my MySql server to my Elasticsearch server. 我正在尝试使用logstash将MySql服务器上的所有数据同步到我的Elasticsearch服务器。

I've aleardy learned the basics of logstash.conf, this is my file: 我已经学习了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"
    } 
}

My intention is to copy every table into a Type. 我的意图是将每个表复制到一个Type中。 How do I specify this? 我该如何指定?

edit: "type" instead of "index" 编辑:“类型”而不是“索引” 在此处输入图片说明

Thank you! 谢谢!

What you can do is simply to add a field (using add_field ) in each input denoting the type name which you want the data to be indexed in and then use that variable as the type name in the elasticsearch output. 您可以做的就是简单地在每个输入中添加一个字段(使用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}"
    } 
}

Be aware though that using the same index to host several different mapping types might lead to type conflicts. 请注意,尽管使用相同的索引来承载几种不同的映射类型可能会导致类型冲突。 The short story is that two different fields with the same name in two different types MUST ALWAYS have the same type definition. 简而言之,两个不同类型中具有相同名称的两个不同字段必须始终具有相同的类型定义。 Read more about it in this blog article 在此博客文章中阅读有关它的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM