What Is Elasticsearch?
We guess that most of us have heard about the Elasticsearch, but not everyone thoroughly understands what Elasticsearch is. Elasticsearch is a powerful open-source search and analytics engine using Apache Lucene. It is able to handle a large number of use cases, support multiple tenancies and full-text search on HTTP web interface. In simple words, the Elasticsearch helps to store and map all documents effectively in order to optimize the search and retrieval function. In the scope of this blog post, we will discuss specifically Magento 2 Elasticsearch.
Why Should We Use Elasticsearch In Magento 2?
In all of the e-commerce websites including the ones built on Magento 2, the search is no doubt one of the most pivotal functionalities. An effective search will help the shoppers to find their needed products on the store at ease, which might result in better customer experience and stimulated purchases. On the other hand, the poor search tool can slow down the process of looking for the items and even be the reason for the high buyers’ bounce rates.
Therefore, it’s essential to enhance the search feature in Magento 2 stores, and applying Elasticsearch is one of the best ways to do that. Unfortunately, Magento only integrates Elasticsearch in Magento Open Source 2.3.0 and Magento Commerce edition. For Magento Open Source 2.2.x, you need to install a proper module to have Elasticsearch’s powerful features. Now, there are several options when it comes to Magento 2 Elasticsearch module, both free and paid. In this post, we will show you the guide to install a free one.
Magento 2 Elasticsearch’s Highlights
- Search optimization
- Search autocomplete
- Thesaurus management (synonyms, expansions)
- Advanced price slider
- Multi-select in layered navigation & swatches
- Redirect to product page if there is only one result
- Auto spell checking & stopwords detection
- Customizable filters
- Search under various languages
- Real-time data and analysis
How To Install Elasticsearch In Ubuntu?
As you might know, the Elasticsearch is built on Java, and it requires at least Java 8 (1.8.0_131 or later) to run properly. Therefore, first and foremost, we need to install Java 8 on all the nodes in the cluster.
- Step 1: Updating your system: sudo apt-get update
- Step 2: Installing Java with sudo apt-get install default-jre
- Step 3: Checking your Java version the and you will get the output similar to the following:
- Step 4: Installing Elasticsearch
– First, you must add Elasticsearch’s signing key to verify the downloaded package (or skip this step if you’ve already installed the packages from Elasticsearch):
wget -qO – https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add –
– Second, you need to install the apt-transport-https package:
sudo apt-get install apt-transport-https
– Third, you need to add the repository definition to your system:
echo “deb https://artifacts.elastic.co/packages/6.x/apt stable main” | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
– Fourth, updating your repositories and install Elasticsearch:
sudo apt-get update
sudo apt-get install elasticsearch
– Fifth, updating elasticsearch library:
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-phonetic
- Step 5: Activating Elasticsearch:
sudo -i service elasticsearch start
- Step 6: Configuring Elasticsearch memory:
sudo gedit /etc/elasticsearch/jvm.options
Notes: Deleting 2 lines Xms4g and Xmx4g
- Step 7: Fixing too_many_clauses error
sudo gedit /etc/elasticsearch/elasticsearch.yml
Adding the code “indices.query.bool.max_clause_count: 10024” on the bottom of the page.
- Step 8: Testing how Elasticsearch works
curl -XGET ‘http://localhost:9200/_cat/health?v&pretty’
Like the index of a book, the indexes here are made out of letters. Owing to that, when the customers do the search, the Elasticsearch will produce matches as soon as the query string is entered.
How To Uninstall Elasticsearch In Ubuntu?
In order remove the Elasticsearch, you can run the following commands:
sudo apt-get –purge autoremove elasticsearch
sudo rm -rf /var/lib/elasticsearch/
sudo rm -rf /etc/elasticsearch
How To Install Magento 2 Elasticsearch Module?
To begin with, you must select a proper Elasticsearch version for your Magento store, and then run the correlative composer require:
(Notes: Here we are using the free ElasticSuite)
- Magento 2.0.x Open Source/ Commerce => ElasticSuite 2.1.x latest release: composer require smile/elasticsuite ~2.1.0
- Magento 2.1.x Open Source/ Commerce => ElasticSuite 2.3.x latest release : composer require smile/elasticsuite ~2.3.0
- Magento 2.2.x Open Source/ Commerce => ElasticSuite 2.6.x latest release : composer require smile/elasticsuite ~2.6.0
- Magento 2.3.x Open Source/ Commerce => ElasticSuite 2.7.x latest release : composer require smile/elasticsuite ^2.7.0
Then, you must run composer update to update Magento library.
Next, you need to run the command: php bin/magento setup:upgrade to update the Elasticsearch module.
Finally, don’t forget running the command: php bin/magento indexer:reindex to synchronize all products in your catalog with Elasticsearch.
How To Configure Elasticsearch in Magento 2 Step-by-step?
- Step 1: Log in to your Magento 2 back-end.
- Step 2: Navigate to STORES, click on Configuration (under Settings)
- Step 3: Expand CATALOG section and click on Catalog, choose Catalog Search on the right menu
- Step 3: Complete Magento 2 Elasticsearch related fields
Enter the Minimum Query Length (length of entered text on search bar) at which the store starts using the Elasticsearch.
Enter the Maximum Query Length (length of entered text on search bar), beyond that the Elasticsearch is disabled.
Enter the Number of top search results to cache, which means the number of popular searches that should be stored.
Set Enable EAV Indexer to Yes for better indexation speed.
Set Search Engine to Elasticsearch or Elasticsearch 5.0+ (more recommended).
Enter Autocomplete Limit, the maximum number of search results displayed by search autocomplete function.
Enter your hostname or your server’s IP address, where the Elasticsearch is running, in Elasticsearch Server Hostname.
Enter Elasticsearch Server Port.
Leave Elasticsearch Index Prefix field by default or set a unique one.
Set Enable Elasticsearch HTTP Auth to Yes, and then enter the username and password.
Set specific Elasticsearch Server Timeout in seconds.
Set Enable Search Suggestions to Yes to display search suggestions.
Set Search Suggestions Count, the number of suggestions displayed with each search.
Set Show Results Count for Each Suggestion to Yes to display the count for each suggestion.
Set Enable Search Recommendations to Yes to display the recommendations for search strings.
Specify Search Recommendations Count.
Set Show Results Count for Each Recommendation to Yes to display the count for results with suggestions.
We have shown a detailed instruction to install Elasticsearch in Ubuntu, install Magento 2 Elasticsearch module and configure Elasticsearch on Magento 2 backend. If you are not clear on anything, just leave a comment so we can help!