Skip to content

Instantly share code, notes, and snippets.

@siffash
Created January 29, 2020 09:28
Show Gist options
  • Save siffash/d78348850a3295af3257b43834400009 to your computer and use it in GitHub Desktop.
Save siffash/d78348850a3295af3257b43834400009 to your computer and use it in GitHub Desktop.
Migrate data from MySQL to Elasticsearch using Logstash
sudo logstash -e '
input {
jdbc {
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://domain.com:3306/database?autoReconnect=true&useSSL=false&useCursorFetch=true"
jdbc_user => "admin"
jdbc_password => "password"
jdbc_fetch_size => 1000
statement => "SELECT * FROM everything"
use_column_value => true
tracking_column => "id"
lowercase_column_names => false
}
}
output {
elasticsearch {
document_id => "%{id}"
doc_as_upsert => true
hosts => ["http://localhost:9200"]
index => "tracksy"
}
}
'
@siffash
Copy link
Author

siffash commented Jan 29, 2020

Before that:

  1. Download MySQL connector
  2. Put the .jar files to /usr/local/Cellar/logstash-full/7.4.2/libexec/logstash-core/lib/jars/ (on Mac)
  3. Add mapping to Elasticsearch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment