Spree search kick is a rubygem that uses Elasticsearch and makes searches easy and in a user-friendly fashion.
To get started with spree_searchkick gem, make sure that you have installed Elasticsearch in your system.
Now, the question arises to everyone: what is Elasticsearch? And How to install it? and how does it work with searchkick gem? And many more.
We can go through all the above questions one by one.
What is Elasticsearch?
Elasticsearchis a scalable, distributed, and open-source analytics engine. It allows you to store, search, and analyze huge amounts of data.
It is built on Apache Lucene and has tools for ingestion, enrichment, storage, analysis, and visualization. Elasticsearch offers indexing, storing, and analysis of data, making it easier to search for queries.
It is generally needed when the application has a complex search feature and requirement.
Built-in Elasticsearch Features
Integrating elasticsearch is an exciting way to maximize the capabilities of your e-commerce store. The powerful, real-time, search analytics engine for all types of data. It allows -
- Optimization of quick searches by storing and indexing data
- Efficient retrieval and aggregation of data
- Blazing fast auto-search and auto-complete
- Similar category presentation in E-commerce stores.
The built-in features of Elasticsearch include the following: -
Elasticsearch Index
Index reduces the time it takes to look up data in Elasticsearch. Even when there are millions of products, Elasticsearch exceeds the performance of SQL database query solutions.
Index organizes the data into categories, which then showcase the information when a keyword related to that category is entered. You can also access multiple pieces of indices or categories with it. The data organization in the Spree integrations of Elasticsearch leads to better search result performance.
Elasticsearch Aggregations
Aggregations deliver analytical information across a data set. So if you want to determine which products are quickly selling in your store, then aggregations can perform calculations on data units and deliver the results.
The data is grouped together using statistics and analytics, allowing to gather information when a user-query is presented.
Elasticsearch Cluster and Nodes
When you want to scale your ecommerce store, clusters and nodes are important as they help in replication. A node is a running instance of Elasticsearch, while a cluster is a wide collection of nodes.
While scaling, clusters & nodes reduce redundancy, enabling shards to be properly distributed. It also secures data from overload and other related issues.
Elasticsearch Shards
Data distributed across multiple nodes is known as shards. They are pieces of data rather than a collection. Shards can be replicated in such a way that it leads to redundancy, reducing the time taken for horizontal scalability.
Let's learn how to use Elasticsearch with a spree searchkick gem.
How to install Elasticsearch using Binary?
Prerequisites:
Elastic search requires java to run in any system.
The below command will show you the current version of java:
$ java -version
And, make sure that your JAVA_HOME variable is configured:
$ echo $JAVA_HOME
Installation:
Elasticsearch officially provides an apt repository to install it on the Ubuntu Linux system.
Use the below command to install packages and import the GPG key for Elasticsearch packages.
$ sudo apt-get install apt-transport-https
$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
$ add-apt-repository "deb https://artifacts.elastic.co/packages/7.x/apt stable main"
The below command will add a repository to install the latest Elasticsearch on your system:
$ sudo apt-get update
$ sudo apt-get install elasticsearch
Then, Runs the below commands to update cache and for install Elasticsearch:
$ sudo nano /etc/elasticsearch/elasticsearch.yml
Configurations:
network.hostcluster.namenode.name
After installing Elasticsearch in the system, you can customize this by editing the Elasticsearch configuration file. You can use any editor available in your system.
$ sudo /bin/systemctl enable elasticsearch.service
You are able to change below values in a configuration file:
$ sudo systemctl start elasticsearch.service
$ sudo systemctl stop elasticsearch.service
Now you are ready to launch Elasticsearch. To start automatically Elasticsearch service when the system boots up, you can use the below command.
$ curl -X GET "localhost:9200/?pretty"
Hit the below command to start the Elasticsearch service:
Testing:
gem 'searchkick'
bundle install
gem 'spree_searchkick', github: 'ronzalo/spree_searchkick', branch: '3-1-stable'
bundle exec rails g spree_searchkick:install
bundle exec rails searchkick:reindex:all
You can test the Elasticsearch service using the curl command-line utility. Run the below command to see Elasticsearch cluster details with the version.
The basic requirement for the searchkick gem is fulfilled.
Add searchkick and spree_searchkick gem to your Gemfile.
Install the gem using bundler:
Run the below commands to install dependencies:
The impact of spree searchkick gem using Elasticsearch:
Contact us for a FREE CONSULTATION.Depends on the input it will give auto-suggestion or hint so it provides easy product discovery.
Search result based on what you input:
Read Also: Elasticsearch Engine Integration with Django
Conclusion
In this article, we first learned about Elasticsearch-rails. We also understood the features in the integration of Elasticsearch with your Spree Commerce store. Since developers often use the searchkick, Elasticsearch is important.
The article also addressed the steps to install the tool and integrate with Spree store. We have discussed the prerequisites, configurations, installation, and testing of Elasticsearch Ruby using the searchkick gem for Spree stores.
If you are looking for a Spree Commerce store with Elasticsearch capabilities, contact our expert Ruby on Rails developer. We will get started with your project within 48 hours!