[英]Automate mongodb and elasticsearch sync
我目前正在一个项目中,我们的主数据库是mongodb,对于搜索,我们使用elasticsearch。 我们已经通过Java应用程序将数据插入到mongodb中。 而且我们使用river插件来同步数据。 到目前为止,我们已经通过执行下面提到的shellscript文件手动完成了mongodb和elasticsearch之间的数据同步。 (setup.sh && bash.sh)
//setup.sh
curl -XPOST http://localhost:9200/classdata -d @setup.json
//setup.json
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"classdata": {
"properties": {
"className": {
"type": "string"
},
"jarID": {
"index": "not_analyzed",
"type": "string"
},
"jarFileName": {
"index": "not_analyzed",
"type": "string"
},
"dependencies": {
"properties": {
"methodSignature": {
"type": "string"
},
"dependedntClass": {
"type": "string"
}
}
}
}
}
}
}
//bash.sh
curl -XPUT "localhost:9200/_river/classdata/_meta" -d '
{
"type": "mongodb",
"mongodb": {
"servers": [
{ "host": "127.0.0.1", "port": 27017 }
],
"options": { "secondary_read_preference": true },
"db": "E",
"collection": "ClassData"
},
"index": {
"name": "classdata",
"type": "classdata"
}
}'
但是现在我们的要求已经改变。 现在我们需要自动化该过程,就像将数据插入到mongodb中之后,我们必须在elasticsearch和mongodb之间自动同步数据。 我不知道该怎么做。 如果有人知道如何自动执行此过程,请帮助我。
MongoConnector插件支持MongoDB和Elastic Search之间的数据同步。
1)在您的服务器中安装Mongo Connector。
`pip install mongo-connector`
2)根据目标系统安装文档管理器。 基于目标系统的文档管理器有多种实现方式。 安装一个支持Elastic Search的版本,尤其是您拥有的版本。 例如)
pip install 'mongo-connector[elastic5]'
3)使用源(mongodb)和目标系统的配置启动Mongo Connector。 例如)
mongo-connector -m <mongodb server hostname>:<replica set port> -t <replication endpoint URL, e.g. http://localhost:8983/solr> -d <name of doc manager>
现在,数据将在两个系统之间自动同步。
有关更多信息,请使用以下链接,
https://www.mongodb.com/blog/post/introducing-mongo-connector
https://github.com/mongodb-labs/mongo-connector
https://github.com/mongodb-labs/mongo-connector/wiki/用法%20with%20ElasticSearch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.