2021-03-02 17:02

如何使用logstash同步mysql 多张表的数据到ElasticSearch

王姐姐

大数据

(1135)

(0)

收藏

input {  
    jdbc {  
      jdbc_connection_string => "jdbc:mysql://localhost:3306/数据库名"  
      jdbc_user => "root"  
      jdbc_password => "password"  
      jdbc_driver_library => "mysql-connector-java-8.0.22.jar所在位置"  
      jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
      codec => plain {charset => "UTF-8"}
      record_last_run => true
      jdbc_paging_enabled => "true"  
      jdbc_page_size => "10000"  
      statement => "sql statement"   
      schedule => "* * * * *"  
      type => "表1"  
      tags => "表1"
    }
    jdbc {  
      jdbc_connection_string => "jdbc:mysql://localhost:3306/数据库名"  
      jdbc_user => "root"  
      jdbc_password => "password"  
      jdbc_driver_library => "mysql-connector-java-8.0.22.jar所在位置"  
      jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
      codec => plain {charset => "UTF-8"}
      record_last_run => true
      jdbc_paging_enabled => "true"  
      jdbc_page_size => "10000"  
      statement => "sql statement"   
      schedule => "* * * * *"  
      type => "表2"
      tags => "表2"
    }
}  


output {  
    if [type] == "表1"{
        elasticsearch {
            hosts => ["host1地址"]  
            index => "表1对应的ES索引"  
            document_id => "%{唯一id}"
        }
    }    if [type] == "表2"{
        elasticsearch {
            hosts => ["host2地址"]  
            index => "表2对应的ES索引"  
            document_id => "%{唯一id}"
        }
    }
    stdout {   
        codec => json_lines  
    }  
}

0条评论

点击登录参与评论