Adding Elastic Search
to a Ruby on Rails
application can be a bit tricky, as there isn't any end to end documentation for the same, like how to install and run elastic search for development, staging and production, how to add analyzers and tokenizers for any fields in db, how to add filters and all.
This is a series of posts for the same, we will cover the above topics in 3 parts:
- Install elastic search(with docker)
- Add logic to Rails application
- Implement Search
In this post we will cover the first part, installing elastic search.
We will be using docker
with docker-compose
for this, as its really handy and requires only a few lines of code to get it up and running.
Steps:
- Install
docker
on your system. I prefer ubuntu or any such single box, and use it fordevelopment
,staging
andqa
environments with different index names for different developers in dev and environments.
You can find instructions over here. - Install
docker-compose
. Relevant instructions can be found here. - ssh into the server you want to install elastic search on.
something likessh username@server_ip
- Create a folder for elastic search in a convenient location.
something likemkdir ~/elastic-search
should be good enough. - Create and edit a new file
vim ~/elastic-search/docker-compose.yml
- Enter the content from this link in that file.
- Edit the file
vim /etc/sysctl.conf
and append a line in the end:
vm.max_map_count=262144 - You can reboot the server, for the change to take effect, or run
sudo sysctl -w vm.max_map_count=262144
for changes in the current session. - Now head over to the folder elastic-search like
cd ~/elastic-search
- Run
sudo docker-compose up -d
- This should fire up the elastic search server on port 9292.
- After a few seconds run
curl localhost:9292
It should return ajson
object with taglineYou know, for Search
.
Now we are ready for our next step! Integrating this elastic search with our Ruby on Rails application.!!