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:

  1. Install elastic search(with docker)
  2. Add logic to Rails application
  3. 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:

  1. Install docker on your system. I prefer ubuntu or any such single box, and use it for development, staging and qa environments with different index names for different developers in dev and environments.
    You can find instructions over here.
  2. Install docker-compose. Relevant instructions can be found here.
  3. ssh into the server you want to install elastic search on.
    something like ssh username@server_ip
  4. Create a folder for elastic search in a convenient location.
    something like mkdir ~/elastic-search should be good enough.
  5. Create and edit a new file vim ~/elastic-search/docker-compose.yml
  6. Enter the content from this link  in that file.
  7. Edit the file vim /etc/sysctl.conf and append a line in the end:
    vm.max_map_count=262144
  8. 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.
  9. Now head over to the folder elastic-search like cd ~/elastic-search
  10. Run sudo docker-compose up -d
  11. This should fire up the elastic search server on port 9292.
  12. After a few seconds run curl localhost:9292
    It should return a json object with tagline You know, for Search.

Now we are ready for our next step! Integrating this elastic search with our Ruby on Rails application.!!