theangryangel / logstash-output-jdbc

JDBC output for Logstash
MIT License
256 stars 101 forks source link

UPDATE Statement Help #124

Closed karnamonkster closed 6 years ago

karnamonkster commented 6 years ago

Environment

I need help with the UPDATE Statement to be passed in the query. Can you please suggest some examples. My input is from Elasticsearch which fetches around 30 fields for which i need to update the database. MySQL database structure is created

theangryangel commented 6 years ago

It's standard SQL... If you're having difficulty I'd suggest researching or employing someone who can assist further. I dont have the time or will to each basic SQL beyond this. There are plenty of tutorials and documentation around to help.

The below example assumes you have something generating events with fields named field1, field2, and id. It also assumes id matches with an existing row in the table.

jdbc {
  driver_class => "com.mysql.jdbc.Driver"
  connection_string => "jdbc:mysql://HOSTNAME/DATABASE?user=USER&password=PASSWORD"
  statement => [ "UPDATE yourtablename SET field1 = ?, field2 = ? where id = ?", "field1", "field2", "id" ]
}