使用logstash同步mysql 多表數據到ElasticSearch實踐


參考樣式即可,具體使用配置參數根據實際情況而定

input {  
    jdbc {  
      jdbc_connection_string => "jdbc:mysql://localhost/數據庫名"  
      jdbc_user => "root"  
      jdbc_password => "password"  
      jdbc_driver_library => "mysql-connector-java-5.1.45-bin.jar所在位置"  
      jdbc_driver_class => "com.mysql.jdbc.Driver"
      codec => plain {charset => "UTF-8"}
      record_last_run => true
      jdbc_paging_enabled => "true"  
      jdbc_page_size => "1000"  
      statement => "sql statement"   
      schedule => "* * * * *"  
      type => "數據庫表名1"  
      tags => "數據庫表名1"
    }
    jdbc {  
      jdbc_connection_string => "jdbc:mysql://localhost/數據庫名"  
      jdbc_user => "root"  
      jdbc_password => "password"  
      jdbc_driver_library => "mysql-connector-java-5.1.45-bin.jar所在位置"  
      jdbc_driver_class => "com.mysql.jdbc.Driver"
      codec => plain {charset => "UTF-8"}
      record_last_run => true
      jdbc_paging_enabled => "true"  
      jdbc_page_size => "1000"  
      statement => "sql statement"   
      schedule => "* * * * *"  
      type => "數據庫表名2"
      tags => "數據庫表名2"
    }
}  

filter {  
    json {  
        source => "message"  
        remove_field => ["message"]  
    }  
}  

output {  
    if [type] == "數據庫表名1"{
        elasticsearch {
            hosts => ["els的host地址"]  
            index => "數據庫表名1對應的els的index"  
            document_id => "%{唯一id}"
        }
    }
    if [type] == "數據庫表名2"{
        elasticsearch {
            hosts => ["els的host地址"]  
            index => "數據庫表名2對應的els的index"  
            document_id => "%{唯一id}"
        }
    }
    stdout {   
        codec => json_lines  
    }  
}  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM