简体   繁体   English

自动化mongodb和elasticsearch同步

[英]Automate mongodb and elasticsearch sync

I am currently working on a project where our main database is mongodb and for searching we use elasticsearch. 我目前正在一个项目中,我们的主数据库是mongodb,对于搜索,我们使用elasticsearch。 We have inserted data in to mongodb by a java application. 我们已经通过Java应用程序将数据插入到mongodb中。 And we used river plugin to sync data. 而且我们使用river插件来同步数据。 Up to now we have done syncing data between mongodb and elasticsearch manually by executing shellscript files mentioned below. 到目前为止,我们已经通过执行下面提到的shellscript文件手动完成了mongodb和elasticsearch之间的数据同步。 (setup.sh && bash.sh) (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"
}
}'

But now our requirement has changed. 但是现在我们的要求已经改变。 Now we need to automate the process, like after inserting data in to mongodb we have to automatically sync data between elasticsearch and mongodb. 现在我们需要自动化该过程,就像将数据插入到mongodb中之后,我们必须在elasticsearch和mongodb之间自动同步数据。 I have no idea how to do that. 我不知道该怎么做。 If some one know how to automate this process please help me. 如果有人知道如何自动执行此过程,请帮助我。

I strongly recommend you monstache . 我强烈建议您蒙大拿 It runs in the background and automately sync data from Mongodb to Elasticsearch. 它在后台运行,并自动将数据从Mongodb同步到Elasticsearch。 And you can configure to specify which db and what kind of operation(insert, update, delete...) you want to sync, the configuration options listed in here 您可以配置为指定要同步的数据库和操作类型(插入,更新,删除...), 此处列出了配置选项

MongoConnector Plugin supports data sync between MongoDB and Elastic Search. MongoConnector插件支持MongoDB和Elastic Search之间的数据同步。

1) Install Mongo Connector in your server. 1)在您的服务器中安装Mongo Connector。

`pip install mongo-connector`

2) Install Doc Manager based on target system. 2)根据目标系统安装文档管理器。 There are various implementations for Doc Manager based on the Target system. 基于目标系统的文档管理器有多种实现方式。 Install the one that supports Elastic Search and in particular the version that you have. 安装一个支持Elastic Search的版本,尤其是您拥有的版本。 Eg) 例如)

 pip install 'mongo-connector[elastic5]'

3) Start Mongo Connector with configurations of the source(mongodb) and target systems. 3)使用源(mongodb)和目标系统的配置启动Mongo Connector。 Eg) 例如)

mongo-connector -m <mongodb server hostname>:<replica set port> -t <replication endpoint URL, e.g. http://localhost:8983/solr> -d <name of doc manager>

Now data will be automatically synced up between the two systems. 现在,数据将在两个系统之间自动同步。

For more information, use the following links, 有关更多信息,请使用以下链接,

https://www.mongodb.com/blog/post/introducing-mongo-connector https://www.mongodb.com/blog/post/introducing-mongo-connector

https://github.com/mongodb-labs/mongo-connector https://github.com/mongodb-labs/mongo-connector

https://github.com/mongodb-labs/mongo-connector/wiki/Usage%20with%20ElasticSearch https://github.com/mongodb-labs/mongo-connector/wiki/用法%20with%20ElasticSearch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM