-
Notifications
You must be signed in to change notification settings - Fork 706
Quickstart
A short guide for the impatient!
Prerequisites:
A running MySQL database with user test
and password test
, a table orders
A terminal / console with commands curl
and unzip
Internet access (of course)
-
Download elasticsearch (current version is 0.19.8, check for the most recent version on http://elasticsearch.org) from
curl -OL https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.8.zip
-
Unpack zip file into you favorite elasticsearch directory, we call it $ES_HOME
cd $ES_HOME
unzip path/to/elasticsearch-0.19.8.zip
-
Install JDBC river plugin (current version is 1.3.2, check for the most recent version, and if you have the file permissions to write into the
plugins
folder. If you have JDBC river plugins installed before, it is recommended to remove the folderplugins/river-jdbc
../bin/plugin -install jprante/elasticsearch-river-jdbc/1.3.2
-
Download MySQL JDBC driver (current version is 5.1.21, check for the most recent version)
-
Add MySQL JDBC driver jar to JDBC river plugin directory
cp mysql-connector-java-5.1.21-bin.jar $ES_HOME/plugins/river-jdbc/
-
Start elasticsearch in terminal window with logging on the console
./bin/elasticsearch -f
-
Start another terminal window, and create a new JDBC river with name
my_jdbc_river
with thiscurl
commandcurl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{ "type" : "jdbc", "jdbc" : { "driver" : "com.mysql.jdbc.Driver", "url" : "jdbc:mysql://localhost:3306/test", "user" : "test", "password" : "test", "sql" : "select * from orders" }, "index" : { "index" : "jdbc", "type" : "jdbc" } }'
-
The river runs! Watch the log on the elasticsearch console for the river activity. When the river fetched the data and is going to wait for the next cycle (which is by default 60 minutes ahead), you can query your elasticsearch node for the data you just indexed with the following
curl
commandcurl -XGET 'localhost:9200/jdbc/jdbc/_search?pretty&q=*'
-
Enjoy the result!
-
If you want to stop the
my_jdbc_river
river fetching data from theorders
table after the quick demonstration, use thiscurl
command:curl -XDELETE 'localhost:9200/_river/my_jdbc_river'
Now, if you want more fine-tuning, you can drop jdbc
the index, change the mapping for your data, change the index nane or type name, change the river creation settings, play with the fetch interval - whatever you like.