Elasticsearch sync MySQL

Source: Internet
Author: User
Tags ssl connection

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.