Skip to content

A dataset migration tool from MongoDB to Elasticsearch and vice versa. Feel free to contribute

License

Notifications You must be signed in to change notification settings

zeusbaba/mongolastic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongolastic

Build Status license MIT blue mongo.java.driver 3.2.2 brightgreen elastic.java.driver 2.3.4 brightgreen

Mongolastic enables you to migrate your datasets from a mongod node to an elasticsearch node and vice versa. Since mongo and elastic servers can run with different characteristics, the tool provides several optional and required features to ably connect them. Mongolastic works with a yaml configuration file to begin a migration process. It reads your demand on the file and start syncing data in the specified direction.

How it works

First, download the latest mongolastic.jar file.

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

misc:
    dindex:
        name: <string>      (1)
        as: <string>        (2)
    ctype:
        name: <string>      (3)
        as: <string>        (4)
    direction: (em | me)    (5)
    batch: <number>         (6)
    dropDataset: <bool>     (7)
mongo:
    host: <ip-address>      (8)
    port: <number>          (9)
    query: "mongo-query"    (10)
    auth:                   (11)
        user: <string>
        pwd: "password"
        source: <db-name>
        mechanism: ( plain | scram-sha-1 | x509 | gssapi | cr )
elastic:
    host: <ip-address>     (12)
    port: <number>         (13)
    dateFormat: "<format>" (14)
    longToString: <bool>   (15)
    clusterName: <string>  (16)
    auth:                  (17)
        user: <string>
        pwd: "password"
  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. configures whether or not the target table should be dropped prior to loading data. Default value is true (Optional)

  8. the name of the host machine where the mongod is running.

  9. the port where the mongod instance is listening.

  10. data will be transferred based on a json mongodb query (Optional)

  11. as of v1.3.5, you can access an auth mongodb by giving auth configuration. (Optional)

  12. the name of the host machine where the elastic node is running.

  13. the transport port where the transport module will communicate with the running elastic node. E.g. 9300 for node-to-node communication.

  14. a custom formatter for Date fields rather than the default DateCodec (Optional)

  15. serialize long value as a string for backwards compatibility with other tools (Optional)

  16. connect to a spesific elastic cluster (Optional)

  17. as of v1.3.9, you can access an auth elastic search by giving auth configuration. (Optional)

Example

Here is an example of a configuration file:

misc:
    dindex:
        name: twitter
        as: kodcu
    ctype:
        name: tweets
        as: posts
mongo:
    host: localhost
    port: 27017
    query: "{ 'user.name' : 'kodcu.com'}"
elastic:
    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. Additionally, all the test cases can run on Docker using docker-compose.

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

$ java -jar mongolastic.jar -f config.file
Note
Every attempt of running the tool drops the mentioned db/index in the target environment unless the dropDataset parameter is configured otherwise.

License

Mongolastic is released under MIT.

About

A dataset migration tool from MongoDB to Elasticsearch and vice versa. Feel free to contribute

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Java 99.7%
  • JavaScript 0.3%