| Work | Research and Development (R&D) | Engineering | Development | Search | How to deploy Meilisearch on Rails using Digital Ocean
How to deploy Meilisearch on Rails using Digital Ocean


Having a great search experience has become an essential part of most user-facing applications and to meet this need, more and more apps are moving towards using dedicated search engine services such as Algolia and ElasticSearch. These search engines are attractive as they don't have the data modelling and performance constraints that relational databases (Postgres, MySQL, etc) have. With document based search, search items are JSON objects which can be structured however you like -- you can pull data from as many models as you'd like without the need for joining multiple tables together.

I recently came across Meilisearch which is a light-weight open-source search engine replacement of Algolia and ElasticSearch. Meilisearch is still relatively new and they haven't done their major 1.0 version release yet -- at the time of writing, they're still on v0.29.

Why switch from Algolia or ElasticSearch?

So why switch from existing search engine solutions?

Algolia is proprietary software which offers its software as a hosted service via a search-as-a-service pricing. This volume based pricing is based on the number of indexed documents and requests which can get quite expensive if you're working with a lot of data. Also, with Algolia, everything is run on their infrastructure which gives you less control of your data.

ElasticSearch on the other hand is mostly open source and can be self-hosted on your own infrastructure. That said, I've worked with ElasticSearch for several years and it has always felt "heavy" . First, managing ElasticSearch always seems to be more complex than anticipated -- ElasticSearch uses JVM (Java Virtual Machine) which is resource intensive and as you scale up, memory management issues don't seem to go away where you're constantly concerned about the health of each of your clusters. Second, ElasticSearch does a lot and because it supports so many features, at times, it can feel overly complex. It can be used for your user-facing application search (aggregations, synonyms, weights etc) but it can also be used for infrastructure observability (logging, alerting) via the ELK stack (ElasticSearch, Kibana, Logstash). Sometimes I find myself just wanting a boring solution that does one thing really well.

Getting started with Meilisearch

For testing out Meilisearch I used Ruby on Rails application and followed the GoRails guide How to add Search in Rails using Meilisearch.

Migrating Rails from Searchkick + ElasticSearch to Meilisearch



gem 'searchkick', '4.6.3'


gem 'meilisearch-rails', '~> 0.7.3'



  ## post.rb


  def search_data
      id: id,
      title: title,
      description: description,
      created_at: created_at,
      updated_at: updated_at


  ## post.rb

  include MeiliSearch::Rails

  meilisearch do 
    attribute :id
    attribute :title
    attribute :description
    sortable_attributes [:created_at, :updated_at]

Rake Tasks