本篇为此系列的第一篇,能写多少看状态~~!
mysql-river
不多说,开篇上网址:https://github.com/jprante/elasticsearch-jdbc里面教程讲的比较清楚,但是在同步mysql的时候的过程中出现了诸多问题(我用的是jdk1.7.0 ES1.5.2),不是ClassNotFound,就是各种Invokexxx之类的错误(修复后,就没图了。。。)折腾了好久,发现是mysql-jdbc的版本问题。
按教程中给的http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/1.5.2.0/elasticsearch-jdbc-1.5.2.0-dist.zip库始终报错,不知为何,还请大神指点。
解决方法如下:下载http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.5.0.5/elasticsearch-river-jdbc-1.5.0.5.jar并拷贝到$ES_HOME/lib下便解决了。
然后是创建river,如下
curl -XPUT 'localhost:9200/_river/[type_name]/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://[IP]:[port]/[database]",
"user" : "root",
"password" : "123456",
"sql" : "select * from [table_name]",
"index" : "[index_in_ES]",
"type" : "[type_in_ES]"
}
}'
mongodb-river
惯例:https://github.com/richardwilly98/elasticsearch-river-mongodb
mongodb要搭成集群模式
建立river如下
curl -XPUT "192.68.3.130:9200/_river/river_name/_meta" -d '
{
"type": "mongodb",
"mongodb": {
"servers":
[
{ "host": "192.168.1.111", "port": 888 },
{ "host": "192.168.1.112", "port": 889 }
],
"options": {
"secondary_read_preference" : true
},
"credentials":
[
{ "db": "admin", "user": [user_name], "password": [password] }
],
"db": "test",
"collection": "testES"
},
"index": {
"name": "testes_index",
"type": "type_index"
}
}'
目前ES已经升级到了2.1.0,悲剧的是官方已经发布公告,不支持river迁移数据了!!!
参考内容:https://www.elastic.co/blog/deprecating-rivers