Elasticsearch sync MySQL plugin selected ELASTICSEARCH-JDBC, the reason is high activity, continuous update, the latest version compatible with elasticsearch-2.3.3.
First, download
: HTTPS://GITHUB.COM/JPRANTE/ELASTICSEARCH-JDBC
After downloading, there is bin, lib2 directory.
Second, MySQL configuration
Make sure MySQL is available and create a new test database in MySQL
mysql>create database test;
Create a new user table
int(10nullchar(10));
Insert a few data.
into test values("1","zhangsan"into user values("2","LiSi"into user values("3","WangWu"into user values("4","MaLiu");
View All data:
mysql> select * from user;+----+----------+| id | name |+----+----------+| 1 | zhangsan || 2 | LiSi || 3 | WangWu || 4 | MaLiu |+----+----------+4 rows in set (0.00 sec)
So the data in MySQL is ready.
third, import data
Create a new Odbc_es folder, create a new mysql_import_es.sh
script, and script the contents:
bin=/users/yaopan/documents/bropen/elasticsearch-jdbc-2.3.2.0/binlib=/users/yaopan/documents/bropen/elasticsearch-jdbc-2.3.2.0/libecho ' {"Type":"JDBC","JDBC": {"Elasticsearch.autodiscover":true,"Elasticsearch.cluster":"Bropen","url":"Jdbc:mysql://localhost:3306/test","User":"Root","UseSSL":"true","Password":"123456","SQL":"SELECT *, id as _id from user","Elasticsearch": {"Host":"127.0.0.1","Port":9300},"Index":"Test","Type":"User"}} ' | Java-cp"${lib}/*"-dlog4j.configurationfile=${bin}/log4j2.xml Org.xbib.tools.Runner Org.xbib.tools.JDBCImporter
Where bin and Lib use an absolute path.
Add executable permissions:
a
Execute script:
./mysql_import_es.sh
An SSL connection warning was reported with no errors. If Error: Could not find or load main class org.xbib.tools.Runner
such errors occur, there is a good chance that there is a problem with the bin and lib paths.
To view the results of the import:
http://localhost:9200/test/user/_search?pretty
Head Plug-in view:
Reference Articles
Elasticsearch sync MySQL
ELASTICSEARCH-JDBC implementing MySQL sync to Elasticsearch in-depth explanation
Elasticsearch sync MySQL