Marwan Roushdy
Marwan Roushdy

Reputation: 1230

How to get elastic search to play with MongoDb and node.js?

I am fairly new to both mongodb and node.js but recently got everything to work well for me until I reached the point where I needed to add a full text search to my website. From my research I figured out that Elasticsearch would be a good fit, but I couldnt figure out exactly how to get it to work with node.js and mongodb. I am currently using Heroku and MongoLab to host my application. Here are my questions.

  1. How do I host Elasticsearch?

  2. How do I make all my mongo data available to elasticsearch do I use a river or do I manually inset and delete all data?

    I found something this river but I am not quite sure how to make this happen automatically and where to host it.

  3. How do I query Elasticsearch from node.js? Is there a package that allows for this?

Edit:

Question 2 is really what I am struggling with. I have also included question 1 and 3 to help people that are new to the topic and coming from google.

Upvotes: 12

Views: 7260

Answers (3)

swapnil2993
swapnil2993

Reputation: 1394

  1. You can host on your own server or use aws elasticsearch service or use elastic cloud provided by elasticsearch.
  2. Try any of the following three solutions:- i) Try using mongoosastic. NPM package ii) Use mongo-connector. iii) python script for indexing data to elasticsearch
  3. elasticsearch-js. The javascript client library

Upvotes: 0

Ferhat Sobay
Ferhat Sobay

Reputation: 261

Searchly.com (Aka SearchBox.io)introduced a new feature crawlers includes MongoDB crawler. It fetches data from a given collection and syncs periodically to ElasticSearch. Check http://www.searchly.com/documentation/crawler-beta/

Upvotes: 1

Gal Ben-Haim
Gal Ben-Haim

Reputation: 17803

1) either on your own server/VM/whatever.. or with a hosted service such as https://searchbox.io/

2) you can create a script to index your existing data and then index new data once its created, or use a river to index your current database.

3) ElasticSearch is a simple HTTP API, you can make your own requests using the 'http' module or simplify it with something like https://github.com/mikeal/request

you can also use a 3rd party library like https://github.com/phillro/node-elasticsearch-client

Upvotes: 8

Related Questions