sync MongoDB collections to ElasticSearch
10K+
Why does this exist?
Mongo2ES runs as a Meteor application, so you need to have Meteor installed, first.
curl https://install.meteor.com/ | sh
then clone, set env variables and run it
git clone https://github.com/Alino/Mongo2ES.git
cd Mongo2ES
export elasticsearchHost="http://127.0.0.1:9200";
export MONGO_URL="mongodb://127.0.0.1:27017/dbname?replicaSet=rs&readPreference=primaryPreferred&w=majority&connectTimeoutMS=60000&socketTimeoutMS=60000"
meteor --port 3001
git clone https://github.com/Alino/Mongo2ES.git && cd Mongo2ES
docker build -t kuknito/mongo2es .
docker run --name Mongo2ES -d \
-e ROOT_URL=http://localhost:3001 \
-e MONGO_URL="mongodb://127.0.0.1:27017/dbname?replicaSet=rs&readPreference=primaryPreferred&w=majority&connectTimeoutMS=60000&socketTimeoutMS=60000" \
-e MONGO_OPLOG_URL=mongodb://127.0.0.1:27017/local \
-e elasticsearchHost="127.0.0.1:9200" \
-p 3001:80 \
kuknito/mongo2es
note: the docker image is also available at docker hub as an automated build. https://hub.docker.com/r/alino/mongo2es/
meteor add alino:mongo2es
https://github.com/Alino/alino-mongo2es
| env variable | description |
|---|---|
| MONGO_URL | MongoDB url |
| MONGO_OPLOG_URL | MongoDB oplog url |
| elasticsearchHost | URL which defines your ES host. (including port) |
| logitHost | URL of your logstash host (optional) |
| logitPort | logstash port (optional) |
If you want to sync MongoDB to ElasticSearch, you must define which collections you want to watch. For that, you have to write your watchers.
If you are ready to write your own watchers,
go and create new file watchers.js in the project root.
Then you create a watcher by creating new object from Mongo2ES class:
if(Meteor.isServer) {
Meteor.startup(function() {
new Mongo2ES(options);
});
}
options = {
collectionName: // String - name of the mongoDB collection you want to watch
ES: {
host: // String - url of your ElasticSearch host where you want to copy the data to.
index: // String - ElasticSearch index
type: // String - ElasticSearch type
},
transform: // Function - modify the document before copying it to ElasticSearch. Takes 1 argument - the document and should return the modified document.
// NOTE: if you 'return false' within this function and then the transportation of this document would be totally skipped!
copyAlreadyExistingData: // Boolean - true if it should copy all existing data in this collection ( default: false )
}
You can get inspired from this example file
watchersExample.md
watcher = new Mongo2ES(options); // create a watcher and put it into a variable
watcher.stopWatch() // stops the watcher
there are currently 2 options for logging in Mongo2ES.
console.log() doesBoth logging options are using Meteor package alino:logit
MONGO2ES_VERBOSE=true when creating the containerverbose: true in options when instantiating Mongo2ES.Content type
Image
Digest
Size
293.1 MB
Last updated
about 10 years ago
docker pull alino/mongo2es