ElasticSearch (ES) is a powerful Full Text Search Engine based on Apache Lucene.
A key characteristic of ElasticSearch is that it’s distributed at it’s core, meaning that you can easily scale it horizontally for the purpose of redundancy or performance.
ElasticSearch can also be used as data store engine, but it has some disadvantages:
1) Security - ElasticSearch does not provide any internal security or access control system. The only way to protect ES from external access is with a firewall.
2) Computation – There is limited support for advanced computation on the database side.
3) Data Availability – Data in ElasticSearch is available in “near real time”, - meaning that if you submit a comment to a post and refresh the page, it might not show up as the index is still updating.
4) Durability – ES is distributed and relatively stable, but backups are not as high priority as in other data store solutions. This is an important consideration when ElasticSearch is your primary data store.
To start ElasticSearch implementation into Rails application, we need to choose proper gem.
You can choose between:
https://github.com/toptal/chewy from Toptal team and https://github.com/elastic/elasticsearch-ruby from Elastic.
In this article I show how to use elasticsearch-ruby in our project prototype.
So, we start from our gems:
And two lines of code into our Job model:
Let’s populate our search index:
Great, let’s tale a look into our seeds.
Let’s call to search method on our Job model with search string:
As you see, basic implementation is pretty easy, in the next posts I’ll write about Chewy gem and using ElasticSearch as data storage layer.