MongoDB Index with ElasticSearch

I already have MongoDB and installed Elasticsearch with Mongoriver . So I created my river:

$ curl -X PUT localhost:9200/_river/database_test/_meta -d '{ "type": "mongodb", "mongodb": { "servers": [ { "host": "127.0.0.1", "port": 27017 } ], "options": { "secondary_read_preference": true }, "db": "database_test", "collection": "event" }, "index": { "name": "database_test", "type": "event" } }' 

I just want to receive events from country:Canada , so I'm trying:

 $ curl -XGET 'http://localhost:9200/database_test/_search?q=country:Canada' 

And I get:

 { "took": 2, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 0, "max_score": null, "hits": [] } } 

I am searching the web and I read that I must first index my collection with Elasticsearch (lost link). Should I index my mongod? What to do to get results from an existing MongoDB collection?

+7
mongodb elasticsearch
source share
1 answer

The mongodb river relies on the MongoDB operation log to index documents, so you need to create your mongo database as a replica set. I assume that this is not enough for you, so when you create a river, the initial import does not see anything for indexing. I also assume that you are running Linux and you have a cli shell tool handle, so try this:

Follow these steps:

  • Make sure attachment plugins for adapter cards are also installed.
  • Back up your database with mongodump
  • edit the mongodb.conf file (usually in the /etc/mongodb.conf file, but it depends on how you installed it) and add the line:

    replSet = rs0

    "rs0" is the name of the replica set, it can be anything you like.

  • reboot the mongo and then log in to your console. Type of:

    rs.initiate()
    rs.slaveOk()

The rs0:PRIMARY> will change to rs0:PRIMARY>

  • Now create your river in the same way as in the question and restore your database using mongorestore. Elasticsearch should index your documents.

I recommend using this plugin: http://mobz.imtqy.com/elasticsearch-head/ to navigate your indexes and rivers and make sure your data has been indexed.

If this does not work, write down which versions you use for mongodb-river-plugin, elasticsearch and mongodb.

+18
source share

All Articles