Hi everyone!,
In this article, I will introduce you a small intro about Mongolastic written in Java 8.What data you have in your MongoDB can also be included into your ElasticSearch and vice versa using this tool. You can perform the aforementioned facilities by providing a file having a yaml characteristic.

How it works

First, download the latest mongolastic.jar file.

Second, give a yaml file which must contain the following structure:

        name: <string>   (1)
        as: <string>     (2)
        name: <string>   (3)
        as: <string>     (4)
    direction: <em | me> (5)
    batch: <number>      (6)
    host: <string>       (7)
    port: <number>       (8)
    query: "mongo-query" (9)
    host: <string>       (10)
    port: <number>       (11)
1 the database/index name to connect to.
2 another database/index name in which documents will be located in the target service (Optional)
3 the collection/type name to export.
4 another collection/type name in which indexed/collected documents will reside in the target service (Optional)
5 direction of the data transfer. the default direction is me (that is, mongo to elasticsearch). You can skip this option if your data move from mongo to es.
6 Override the default batch size which is normally 200. (Optional)
7 the name of the host machine where the mongod is running.
8 the port where the mongod instance is listening.
9 data will be transferred based on a json mongodb query (Optional)
10 the name of the host machine where the elastic node is running.
11 the transport port where the transport module will communicate with the running elastic node. E.g. 9300 for node-to-node communication.

Here is an example of a configuration file:

        name: twitter
        as: kodcu
        name: tweets
        as: posts
    host: localhost
    port: 27017
    query: "{ 'user.name' : 'kodcu.com'}"
    host: localhost
    port: 9300

the config says that the transfer direction is from mongodb to elasticsearch, mongolastic first looks at the tweets collection, where the user name is kodcu.com, of the twitter database located on a mongod server running on default host interface and port number. If It finds the corresponding data, It will start copying those into an elasticsearch environment running on default host and transport number. After all, you should see a type called “posts” in an index called “kodcu” in the current elastic node. Why the index and type are different is because “dindex.as” and “ctype.as” options were set, these indicates that your data being transferred exist in posts type of the kodcu index.

After downloading the jar and providing a conf file, you can run the tool as below:

$ java -jar mongolastic.jar -f config.file
Every attempt of running the tool drops the mentioned db/index in the target environment.


Mongolastic is released under MIT.

No Comments

Post a Comment