Elasticsearch JDBC 導(dǎo)入器
通過(guò)Java數(shù)據(jù)庫(kù)連接(JDBC)從JDBC源獲取數(shù)據(jù)導(dǎo)入到Elasticsearch中。
項(xiàng)目地址:
https://github.com/jprante/elasticsearch-jdbc
問(wèn)題
使用 1.7.0_80 版本的JDK報(bào)錯(cuò):Unsupported major.minor version 52.0
換成 1.8.0_101 版本的JDK之后就可以了。
據(jù)說(shuō)是JDK本身的一個(gè)問(wèn)題。
操作過(guò)程
簡(jiǎn)單的記錄操作過(guò)程,詳情見(jiàn)github。
- 下載
wget http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/2.3.4.0/elasticsearch-jdbc-2.3.4.0-dist.zip
- 解壓縮
unzip elasticsearch-jdbc-2.3.4.0-dist.zip
確定JDBC驅(qū)動(dòng)jar
檢查lib目錄是否有你需要的jdbc驅(qū)動(dòng)jar,如果沒(méi)有需要將相關(guān)jar放到該目錄中。編寫(xiě)一個(gè)導(dǎo)入腳本
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bin=${DIR}/../bin
lib=${DIR}/../lib
echo '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://192.168.1.212:3306/hxx",
"user" : "root",
"password" : "root",
"sql" : "SELECT *, id as _id FROM xxtable",
"index" : "test",
"type" : "rt1",
"metrics": {
"enabled" : true
},
"elasticsearch" : {
"cluster" : "wwh_es_cluster",
"host" : "192.168.1.213",
"port" : 9300
}
}
}' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter
~
- 給腳本添加執(zhí)行權(quán)限然后執(zhí)行