简体   繁体   中英

Time change when using jdbc input plugin in logstash

I have a column create_time which value is '2018-01-12 16:27:59'; When I use jdbc input plugin in logstash to synchronous data to Elastic Search . The time has changed to '2018-01-12T08:27:59.000Z' in es. I know the timezone of es is UTC, which is different from my timezone. How can I fix the data? Here is my config file:

 input {
    jdbc {
      jdbc_connection_string => 'jdbc:mysql://*:3306/*?'
      jdbc_user => '*'
      jdbc_password => '*'
      jdbc_driver_library => 'mysql-connector-java-5.1.45-bin.jar'
      jdbc_driver_class => 'com.mysql.jdbc.Driver'
      statement => 'select * from test where create_time > :sql_last_value'
      use_column_value => true
      tracking_column => "create_time"
      tracking_column_type => "timestamp"
      jdbc_default_timezone => "Asia/Shanghai"
      jdbc_fetch_size => "1000"
      schedule => '* * * * *'
    }
}
output {
    stdout {
        codec => json_lines
    }

    elasticsearch {
        hosts => 'localhost:9200'
        index => 'test-1 '
        document_id => "%{id}"
    }


}

You can set the date format you require in the mappings:

{
  "mappings": {
    "my_type": {
      "properties": {
        "date": {
          "type":   "date",
          "format": "yyyy-MM-dd"
        }
      }
    }
  }
}

Refer Elastic Date Formats

You can also change the select statement and format the date as your require before sending it to logstash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM