Logstash 导入数据到Elasticsearch

input {
  jdbc {
        jdbc_driver_library => "/path_to_mysql/mysql-connector-java-5.1.40.jar"
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/dbname?useSSL=false&useUnicode=true&characterEncoding=utf8"
        jdbc_user => "*"
        jdbc_password => "*"
        statement => "
                select id, DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') create_time,
                        DATE_FORMAT(close_time,'%Y-%m-%d %H:%i:%S') close_time
                from table where id > ${MAX_ID:0}
        "
        jdbc_paging_enabled => "true"
        jdbc_page_size => "5000"
  }
}

filter {
  mutate {
        remove_field => ["@timestamp","@version","create_time","update_time"]
        rename => {
                "xxx" => "yyy"  # 字段重命名
        }
  }
}

output {
  stdout {
        codec => json_lines
  }
  elasticsearch {
        hosts => ["127.0.0.1:8200"]
        index => "index_name"
        document_id => "%{id}"
        document_type => doc_name
  }
}

你可能感兴趣的:(ElasticSearch)