Mohamed Abbas | Architect Magento | Tech Blogger | Magento Trainer

Mohamed Abbas
Mohamed Abbas
Architect Magento | Tech Blogger | Magento Trainer

Elasticsearch in Magento 2

Elasticsearch is a powerful and flexible search engine that can significantly improve search functionality in Magento 2 stores, enhancing features such as search suggestions, autocomplete, and relevance-based results. Let’s go through how Elasticsearch integrates with Magento 2, its advantages, and the steps for creating custom indexes.

Key Features of Elasticsearch in Magento 2
  • Advanced Error Correction:
  • Fuzzy Search: Corrects minor typos and suggests relevant items.
  • Phonetic Search: Suggests products with similar pronunciation.
  1. Alternative Suggestions: Provides alternatives if no exact match is found.
  2. Multilingual Full-text Search: Expands search across different languages.
  3. Synonym Support: Allows searching by synonyms and ignoring stopwords for precise results.
  4. Enhanced Filtering and Navigation: Includes advanced sorting, price sliders, multi-select in layered navigation, and swatch support.
Elasticsearch Highlights
  • Search Optimization and Autocomplete
  • Thesaurus Management: Manage synonyms and expansions for more relevant results.
  • Auto Spell-check and Stopword Detection
  • Customizable Filters
  • Real-time Data and Analysis: Provides immediate search results with robust data handling.

Custom Search on Elasticsearch
Using the Elasticsearch client library, you can perform custom searches on a specified index by setting parameters such as index name, type, search query, and result size.

Basic Elasticsearch REST API Commands
Here are some useful curl commands for interacting with Elasticsearch:

List All Indexes:

				
					curl -X GET 'http://localhost:9200/_cat/indices?v'

				
			

List All Documents in an Index:

				
					curl -X GET 'http://localhost:9200/custom_index/_search'

				
			

Query by URL Parameters:

				
					curl -X GET 'http://localhost:9200/custom_index/_search?q=content:faq'

				
			

Query with JSON:

				
					curl -X GET -H 'Content-Type: application/json' 'http://localhost:9200/custom_index/_search' -d '{ "query" : { "match" : { "content": "faq" } } }'

				
			

Add Data:

				
					curl -X PUT -H 'Content-Type: application/json' 'http://localhost:9200/custom_index/_doc/2' -d '{ "content": "testing" }'

				
			

Update Document:

				
					curl -X POST -H 'Content-Type: application/json' 'http://localhost:9200/custom_index/_doc/2/_update' -d '{ "doc" : { "testing": 50000 } }'

				
			

Delete an Index:

				
					curl -X DELETE 'http://localhost:9200/custom_index'

				
			

Elasticsearch’s speed, scalability, and flexibility make it ideal for Magento 2 stores handling large data volumes and complex search requirements. This custom indexing and search solution allow businesses to offer precise, real-time results, improving customer experience and boosting conversion rates.

Picture of Mohamed Abbas

Mohamed Abbas

Technical Lead | Magento Architect