1、安装Python环境-3.7版本
下载地址:https://www.python.org/download/releases/2.7/
2、通过pip安装mongo-connector
pip install mongo-connector[elastic5]
3、安装elastic2-doc-manager
pip install elastic2-doc-manager
4、开启mongodb数据库副本集
配置文件中添加oplogsize和replset信息,以副本集模式启动服务。
在mongodb数据库命令界面执行如下命令:
config =
{ _id:"myDevReplSet",
members:[{_id:0,host:"127.0.0.1:27017"}]
}
rs.initiate(config)
rs.status()
5、执行同步命令
同步单个表:
mongo-connector -m localhost:27017 -t localhost:9200 -d elastic2_doc_manager -n test.table1
同步test数据库中的table1表【在es中,index即为test】,n这个属性就是指定要同步的collection.
同步多个表:
mongo-connector -m localhost:27017 -t localhost:9200 -d elastic2_doc_manager -n test.table1,test.table2,test.table3
6、测试同步
打开浏览器,输入以下网址(默认IP及端口)来查看是否同步成功:添加链接描述
7、数据测试
插入一条测试数据,查看es中是否有此条信息。