Elastic Search Connect to Mongo Database Server

basically, I know the difference between MongoDB and the ES. In my server I have installed MongoDB instance separately will name it as (MDB1) and I installed ES instance separately will name it as (ESS). Currently, I am working on document management system, daily storing millions different kind of document information in Mongo DB. I have browsed many websites but I didn't get my answer as expected.

My question is, I want to connect ESS to MDB1, coz I using ES to search and analyze the data. Is there have any method to connect ES to existing MongoDB instance. (I am using C#.net)

1 Like

There is no official connector from the Elasticsearch side. There are third-party connectors you can use. You can also do http bulk update queries to load data to ES.

Configure MongoDB on Elasticsearch

  1. Install MongoDB
  2. Configure MongoDB
    port: 27017
    oplogSizeMB: 1024
    replSetName: res0
    dbPath: C:\data\db\rs0
    timeStampFormat: iso8601-utc
    destination: file
    path: C:\data\log\rs0\mongod.log
  • Create two file using above configuration save it as primary.cfg and secondary.cfg.

  • Install as Service:

mongod --config "C:\Program Files\MongoDB\Server\3.6\primary.cfg" --install --serviceName "MongoDB_Primary" --serviceDisplayName "MongoDB Primary"
mongod --config "C:\Program Files\MongoDB\Server\3.6\secondary.cfg" --install --serviceName "MongoDB_Secondary" --serviceDisplayName "MongoDB Secondary"
  • Start services (Primary and Secondary instances):
  1. Connect to the primary database
  2. Use rs.initiate() command
  3. Use rs.add("") command
  4. Use rs.config() command
  5. Use rs.status() command
  6. Install Java latest version and set java home path in variable environment
  7. Install Elasticsearch
  8. Go to Elasticsearch folder and open config folder
  9. Set following configuration in elasticsearch.yml file:
cluster.name: home_server
node.name: gehan-pc
path.data: C:\Elasticsearch\data
path.logs: C:\Elasticsearch\logs
http.port: 9200
http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length
  1. Install following files:
pip install mongo-connector[elastic5]
pip install elastic2-doc-manager[elastic5]
  1. Start Elasticsearch instance
  2. Run this command:
mongo-connector --auto-commit-interval=0 -d elastic_doc_manager -t localhost:9200
  1. Open http://localhost:9200/_cat/indices?v to check is mongo collections sync with Elasticsearch server

Thank you @Gehan_Fernando for sharing your recipe. I updated the format a bit as this can be useful for other members. I hope I did not change anything important (specifically, I updated a bit the mongo config).

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.