ElasticSearch and Spree integration
ElasticSearch is a distributed, RESTful search and analytics engine capable of solving a growing number of use cases. It is developed in Java and is released as open source under the terms of the Apache License.
According to the DB-Engines ranking, ElasticSearch is the most popular enterprise search engine.
The integration of ElasticSearch with your Spree Commerce store can be done quickly and easily following the guidelines mentioned below.
The benefits of using ElasticSearch for your ecommerce business
Powerful, flexible, and reliable search engine is a must-have for an ecommerce store, especially when large amounts of data are involved. The easier and faster customers are able to find what they are looking for, the more likely they are to purchase something in your store.
Speed
ElasticSearch is able to execute complex queries extremely fast. It also caches almost all of the structured queries commonly used as a filter for the result set and executes them only once. For every other request which contains a cached filter, it checks the result from the cache. This saves the time parsing and executing the query improving the speed.
Lots of search options
ElasticSearch implements a lot of features when it comes to search such as customized splitting text into words, customized stemming, faceted search, full-text search, auto-completion, and instant search. Also, fuzzy search is good for spelling errors. You can find what you are searching for even though you have a spelling mistake. Auto-completion and instant search refer to searching while the user types. It can be simple suggestions of existing tags, trying to predict a search based on search history, or just doing a completely new search for every keyword.
Scalability
As ElasticSearch has a distributed architecture it enables to scale up to thousands of servers and accommodate petabytes of data. The customers then need not manage the complexity of distributed design as it has been done automatically.
Multi-tenancy
Often, you have multiple customers or users with separate collections of documents, and a user should never be able to search documents that do not belong to them. This often leads to a design where every user has their own index. Often, this leads to having too many indexes. One larger ElasticSearch index is actually better.
Flexibility
Numbers, text, geo, structured, unstructured. All data types are welcome.
Application search, security analytics, metrics, and logging only scratch the surface of how companies around the world are relying on Elasticsearch to solve a variety of challenges.
How to integrate ElasticSearch with Spree
There are 3 popular Rails gems which you can use to integrate ElasticSearch with your Spree application:
1. https://github.com/toptal/chewy
2. https://github.com/elastic/elasticsearch-rails
3. https://github.com/ankane/searchkick
All of them can be easily integrated thanks to the well-designed Spree’s database schema. What’s more, Spree provides an abstraction for implementing products search (check out https://github.com/spree/spree/blob/master/core/app/models/spree/app_configuration.rb#L70). If you want to implement a search of other entities, just follow the instructions provided by the gems – Spree is just a regular Rails app so there shouldn’t be any additional problems.
It doesn’t matter which gem you’ll choose – the integration will go smoothly. Spree models are so flexible that adding a search layer is not big deal. – Piotr Leniec, Senior Fullstack Developer, Spark Solutions
Example of ElasticSearch and Spree integration
Greetabl is an online one-stop-shop for creatively-curated gifts and greetings that are personalized with Instagram photos, packaged and sent in just a few clicks. The company uses Spree for its eCommerce platform and ElasticSearch for quickly searching and filtering millions of records.
Read more: Greetabl’s Success Story