mysql导入到elasticsearch

时间:2024-06-14 22:35:56
JDBC importer for Elasticsearch 

Java Database 连接(JDBC) 导入运行获取数据从JDBC 源

安装:

1.在下面的步骤 替换<version>为一个版本,比如 1.7.0.0

2.下载JDBC importer  版本
wget http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/<version>/elasticsearch-jdbc-<version>-dist.zip 3.unpack unzip elasticsearch-jdbc-<version>-dist.zip 4. 到unpack 目录(我们调用 $JDBC_IMPORTER_HOME) 进入 elasticsearch-jdbc-<version> 5.如果你没有找到JDBC 驱动包在lib directory,下载它 放到lib文件夹下 zjtest7-redis:/usr/local/elasticsearch-jdbc-2.3.4.0/lib# ls -ltr *jdbc*
-rw-r--r-- 1 root root 216932 Feb 18 2015 jdbc-driver-csv-1.0.0.jar
-rw-r--r-- 1 root root 129248 Aug 2 21:26 elasticsearch-jdbc-2.3.4.0.jar 6.修改脚本在bin目录下 elasticsearch 版本:
elasticsearch-2.3.4 JDBC importer 版本 elasticsearch-jdbc-2.3.4.0 zjtest7-redis:/odbc_es# cat mysql_import_es.sh
bin=/usr/local/elasticsearch-jdbc-2.3.4.0/bin
lib=/usr/local/elasticsearch-jdbc-2.3.4.0/lib
echo '{
"elasticsearch.autodiscover":true,
"elasticsearch.cluster":"es_cluster",
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://192.168.32.218:3306/zjzc",
"user" : "root",
"password" : "1234567",
"sql" : "select * from ClientActionTrack where startTime>=\"2016-09-0 00:00:00\"",
"elasticsearch" : {
"cluster" : "es_cluster",
"host" : "192.168.32.80",
"port" : 9300
},
"index" : "logstash-clientactiontrack",
"type" : "ClientActionTrack"
}
}' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter