After almost two weeks and several re-installs and fresh installs, I finally got to integrate mongodb and elastic search. Here is a step by step procedure on how to integrate them.
If you follow this procedure carefully, it will prevent errors like
Exception: java.lang.NoSuchMethodError: com.mongodb.Mongo.fsyncAndLock()
{
“error” : “IndexMissingException[[testmongo] missing]”,
“status” : 404
}
Follow these guide to install MonogDB and Elastic Search
After you installed them, its time to install elastic search river.
Download the snapshot from here. Extract it and copy its contents to elastic_search_root/plugins/plugins/mongodb_river
Note: The initial implementation tutorial give on the git page points to a older version of the snapshot and it doesn’t work with the latest versions of elastic search and mongodb.
Installing the mongodb river
Run the following two commands to install the mongodb river. If you are on a slow connection, the first command can take more than 15 minutes.
ES_HOME/bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/1.4.0
ES_HOME/bin/plugin -install richardwilly98/elasticsearch-river-mongodb/1.4.0
After you install both of them, restart elasticsearch.
ES_HOME/bin/service/elasticsearch restart
Enable replica sets in mongodb by following this tutorial
Tell elastic search to index the “person” colletion in testmongo database by issuing the following command in your terminal
curl -XPUT 'http://localhost:9200/_river/mongodb/_meta' -d '{ "type": "mongodb", "mongodb": { "db": "testmongo", "collection": "person" }, "index": { "name": "mongoindex", "type": "person" } }'
add some data to the mongodb through mongo terminal
use testmongo var p = {firstName: "John", lastName: "Doe"} db.person.save(p)
Use this command to search the data
curl -XGET 'http://localhost:9200/mongoindex/_search?q=firstName:John'