elasticsearch从mysql导入数据

时间:2023-03-09 04:24:10
elasticsearch从mysql导入数据

详细:https://github.com/jprante/elasticsearch-jdbc(最下面有各数据库的导入方法说明)

elasticsearch版本为1.5.2

1、下载 elasticsearch-jdbc 1.5.2.0

wget http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/1.5.2.0/elasticsearch-jdbc-1.5.2.0-dist.zip

2、解压 elasticsearch-jdbc 1.5.2.0

unzip elasticsearch-jdbc-1.5.2.0-dist.zip

3、配置 elasticsearch-jdbc 1.5.2.0

新建一个.sh文件:

 vi /usr/local/elasticsearch-jdbc-1.5.2.0/bin/import.sh
#!/bin/bash
set -e bin=/usr/local/elasticsearch-jdbc-1.5.2.0/bin
lib=/usr/local/elasticsearch-jdbc-1.5.2.0/lib
echo '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://12.43.18.29:3306/db_1",
"user" : "admin",
"password" : "948",
"sql" : "select * from ach;",
"index": "db_1",
"type": "ach"
}
}' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter

4、执行导入

./import.sh

5、测试导入结果

curl -XGET ‘localhost:9200/db_1/ach/_search?pretty&q=*’

*注意导入不同的表时修改sql和type

增量导入数据:(自带定时更新不符合)

请注意增量导入sql串的写法,

“select * from mon where tTime >\”2015-12-21 04:59:59\” “,而不是

“select * from mon where tTime >‘2015-12-21 04:59:59’ “

导入不成功可以去目录下看log日志

数据导入参考:

http://www.open-open.com/lib/view/open1431071580335.html