LogStash如何通过jdbc 从mysql导入elasticsearch

复制代码
input {
    stdin {
    }
    jdbc {
      # mysql jdbc connection string to our backup databse
      jdbc_connection_string => "jdbc:mysql://localhost:3306/userdb?useUnicode=true&characterEncoding=utf-8&useSSL=false"
      # the user we wish to excute our statement as
      jdbc_user => "user"
      jdbc_password => "pass"
      # the path to our downloaded jdbc driver
      jdbc_driver_library => "mysql-connector-java-5.1.40-bin.jar"
      # the name of the driver class for mysql
      jdbc_driver_class => "com.mysql.jdbc.Driver"
      jdbc_paging_enabled => "true"
      jdbc_page_size => "50000"
      statement_filepath => "mysqltestsql.sql"
      schedule => "* * * * *"
      type => "jdbc"
      use_column_value => true
      tracking_column => id
      last_run_metadata_path => "C:\logstash-5.2.0\bin\last_run_metadata_path\last_run_metadata_path"
    }
}

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

output {  
    elasticsearch {
        action => "index"
        hosts => ["http://localhost:9200"] 

        index => "mysqltestdb2"
        #index => "user"
        workers => 1
    }
     #stdout {
         #codec => rubydebug
         #codec => json_lines
     #}
}
复制代码

 

 mysqltestsql.sql

select id, name from userinfo WHERE id > :sql_last_value

 

posted @   iDEAAM  阅读(704)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
点击右上角即可分享
微信分享提示