Search functionality and complex cross-model searching are becoming more popular. Here’s why we chose Algolia over Elasticsearch at Edukate to deliver smarter results to our users.
Edukate’s content library includes tons of videos, articles, and custom content. We also have benefits information and links.
A high-performance and natural-feeling search engine is important to our user experience. As a result, efficient solutions to query databases are a must. We want to deliver accurate search results quickly and have an engine that scales as we add more resources.
As Edukate grew, our search needs changed. When it was time to find a new search engine, we compared Algolia and Elasticsearch.
Choosing Elasticsearch First
Originally, we chose Elasticsearch because of its out-of-the-box document search capability.
Edukate is built with Ruby on Rails. So we used the wrapper gem, Chewy, to get up and running with Elasticsearch quickly.
Over time, as our content library grew, we began to notice issues. Our application’s performance fluctuated when we searched the indices. Slow search results affect the user experience.
With our index-heavy environment, this was the first indication that we needed a more robust search. To plan for future growth, we started looking for a new search engine.
Ranking-driven results
We recognized the need for our search engine to use a content-ranking formula. This helped deliver relevant content to users.
Also, we wanted our search to get smarter over time.
Therefore, we prioritized the need for a stronger ranking system. Enter Algolia.
Algolia has led the search space for a number of years. In fact, it’s about 200x faster than Elasticsearch.
Elasticsearch’s inability to automatically distribute data across multiple data centers causes this performance difference.
Testing Algolia and Elasticsearch
Next, we tested Algolia and Elasticsearch side-by-side.
The difference in performance was clear from the beginning. Our first tests showed Algolia returned results in as little as 1ms to 11ms. By comparison, Elasticsearch returned results in about 150ms to 300ms. As you can see, the difference was huge.
Below, you can see how long it then takes to deliver those results to the front-end portion of the application.
Algolia:
Elasticsearch:
The code difference for indexing a model is also fairly different with all of the rulings and targets:
Elasticsearch:
define_type Video, delete_if: -> { deleted_at } do
settings analysis: {
analyzer: {
ngram_analyzer: {
tokenizer: 'ngram_tokenizer'
},
tokenizer: {
ngram_tokenizer: {
type: 'nGram',
min_gram: '2',
max_gram: '4',
token_chars: [ 'letter', 'digit' ]
}
}
}
}
field :title
field :description
end
As you can see, Elasticsearch lets us search by video title and description for each video in our library. But we still don’t have a clear ranking for how to decide between two similar videos. There’s a lot of overlap in our content library, so we need nuanced search results.
Additionally, the tokenizer in Elasticsearch isn’t very intuitive.
Another big reason we chose Algolia? You have to set all of the analyzer’s settings every time you search. This makes for clunky code and application bottlenecks.
Algolia:
algoliasearch auto_index: true do
attributes :title, :description
searchableAttributes [‘title’, ‘description’]
customRanking [‘desc(popularity)’]
minWordSizefor1Typo 4
minWordSizefor2Typos 8
hitsPerPage 5
end
With Algolia, we can search by attributes :title, :description and use a custom ranking formula for each result.
Therefore, when two videos are similar, we can use a much simpler tokenizer too.
We’re very excited about the future of Algolia on our platform. Soon, we’d also like to try autocomplete in the search as well.
This will create more personalized searches and make better recommendations to users. Additionally, it will adapt the ranking formula to our content strategy.
Above all, Algolia was simple to launch and set up.
It’s a much better choice for our search needs overall. Migrating from Elasticsearch was also a breeze. And because the Algolia team built a Heroku plugin, we can keep our devops all in one place!
This post was written by Evan Glazer.