logstash-input-jdbc 同時同步多個表的狀況

input {
    jdbc {
      jdbc_connection_string => "jdbc:mysql://localhost:3306/crm?zeroDateTimeBehavior=convertToNull"
      jdbc_user => "root"
      jdbc_password => ""
      jdbc_driver_library => "D:/siyang/elasticsearch-5.2.2/logstash-5.2.2/mysql-connector-java-5.1.30.jar"
      jdbc_driver_class => "com.mysql.jdbc.Driver"
      jdbc_paging_enabled => "true"
      jdbc_page_size => "50000"
      statement_filepath => "filename.sql"
      schedule => "* * * * *"
      type => "jdbc_office"
    }
    jdbc {
      jdbc_connection_string => "jdbc:mysql://localhost:3306/crm?zeroDateTimeBehavior=convertToNull"
      jdbc_user => "root"
      jdbc_password => "" 
      jdbc_driver_library => "D:/siyang/elasticsearch-5.2.2/logstash-5.2.2/mysql-connector-java-5.1.30.jar"
      jdbc_driver_class => "com.mysql.jdbc.Driver"
      jdbc_paging_enabled => "true"
      jdbc_page_size => "50000"
      statement => "SELECT * from sys_user"
      schedule => "* * * * *"
      type => "jdbc_user"
    }
}
output {
 stdout {
        codec => json_lines
    }
    if[type] == "jdbc_office"{
        elasticsearch {
        hosts  => "localhost:9200"
        index => "contacts4"
        document_type => "office1"
        document_id => "%{id}"
        }
    }
    if[type] == "jdbc_user"{
        elasticsearch {
        hosts  => "localhost:9200"
        index => "contacts4"
        document_type => "user1"
        document_id => "%{id}"
        }
    }
}

注意事項,數據庫裏面的字段不要用type,若是有,as成其餘的名字,否則的話,這裏判斷會有異常java

相關文章
相關標籤/搜索