Elasticsearch or MongoDB : Which one is better?



Welcome back to D Guides folks.I am breaking the radio silence after several months and I am hoping to update my 'Programming Guides' section on a weekly basis.Today I am sharing about an interesting topic but at first glance it may look like a monster.But it is not.Do you know what is 'Elasticserach'?Elasticsearch is a document oriented database which will store data in JSON document form.Basically it is a search index or a search engine.As the word 'Elasticsearch' implies this concept is to analyse and search your data in real time.The link below will take you to the official documentation of Elasticsearch.


There is another thing called 'ELK' stack which is the acronym for three open source projects: Elasticsearch, Logstash and Kibana. As I mentioned earlier Elasticsearch will help you to store,analyse and search data in real time. Kibana is a platform to visualise data you feed in to Elasticsearch.Logstash is  a server side data processing pipeline.The outcome becomes more meaning full when using ELK stack than using just Elasticsearch for you application.But now it has become more powerful with more tools(Beats) and now it is known as Elastic Stack.I am not going to go explain deeply about these tools and platforms.If you want  separate tutorials regarding them put a comment below and I will write a separate series regarding Elastic Stack.


Image result for elk stack and mongodb

Next question is why use a Elastic Stack with MongoDB.In an enterprise level application complex and heavy queries will take a considerable amount of time to query and send data to the front end or the user interfaces.Using NoSQL databases over SQL databases will not solve this problem. Elasticsearch is a great solution to reduce that time and make user experience of your application enjoyable. Nowadays every software application/web application has a search functionality.Using Elasticsearch we can store mongoDB documents as indexes.In order to do that we have five options.You can user the appropriate option for your system.

  • Using mongo-connector
  • Using a river
  • Using Logstash
  • Using Transporter tool
  • Using Mongoosastic


I will share information about that process in my future tutorials.Each and every process of Elasticsearch is exposed as REST API.There are four main APIs in Elasticsearch.
  1. Index API - Store Documents as Indexes
  2. Get API - Retrieve Indexes
  3. Search API - Query and get result
  4. Put Mapping API - Define own mapping
The most famous use of Elaticsearch is full text search. MongoDB itself provide full text search capability (Now MongoDB Atlas search).But Elasticsearch provide more capabilities and functionalities.Normal practise in the industry is using MongoDB(Any NoSQL Database) as persistent storage and using Elasticsearch for complex search queries.If the system you are building need realtime sorting, filtering or searching using Elasticsearch is the best option.When using Elasticsearch you can provide functionalities like auto complete, suggestions etc very easily.But even in Elasticsearch you may find drawbacks.One major drawback is slowness of writing new data.So when developing your application it is better not to use Elasticsearch as your primary data store.




I am stoping right here otherwise this post becomes too long and it will be boring to read.Hope you all got something in to your knowledge base and will stay with me in the long run.Share among your colleagues and be safe until we meet again.

Comments

Popular posts from this blog

Useful Tools For React Developers

Huawei Nova 2i

Best Tech Gadgets To Gift For Christmas 2017