ElasticSearch Implementation Magento 2
What is Elasticsearch?
Elasticsearch is a powerful, scalable, and highly extensible search engine widely used by large websites. When integrated with Magento 2, it provides fast search results, autocomplete suggestions, search recommendations, and improves overall store performance.
Magento Elasticsearch Architecture
Elasticsearch powers Magento’s storefront search, indexing, layered navigation, and product filtering.
Features of Elasticsearch
1) Advanced Typing Error Correction
Fuzzy Search: Detects close matches (e.g., “sweetshirt” → “sweatshirt”).
Phonetic Search: Suggests items with similar pronunciation (e.g., “llaguing” → “leggings”).
2) Alternative Suggestions
Displays the closest matching results when no exact match is found.
3) Multilingual Full-Text Website Search
4) Support for Alternate Keywords & Ignored Words
5) Full Control Over Sorting Search Results
6) Synonym-Based Search
Example: “Men” = “Man”, “Blue” = “Denim”.
7) Auto-Detect & Ignore Stop Words
Words like “and”, “or”, “to”, “for” are ignored to improve accuracy and performance.
Elasticsearch Highlights
- Search optimization
- Search autocomplete
- Synonyms & thesaurus management
- Advanced price slider
- Multi-select layered navigation
- Auto spell checking
- Redirect if only one result is found
- Custom filters
- Supports multiple languages
- Real-time analytics
Creating Custom Index on Elasticsearch
This describes how to create a custom Elasticsearch index using Magento 2 custom tables.
Files Required:
- indexer.xml – Registers custom indexer name and PHP class.
- mview.xml – Tells Magento when to re-index based on table changes.
- Indexer PHP file – Creates ES index and pushes table rows.
Custom Search on Elasticsearch
Create an Elasticsearch client instance and specify:
- Index name
- Index type
- Query type and fields
- Result size
Elasticsearch REST API Commands (cURL)
curl -X GET 'http://localhost:9200/_cat/indices?v'
curl -X GET 'http://localhost:9200/custom_index/_search'
curl -X GET 'http://localhost:9200/custom_index/_search?q=content:faq'
curl -X GET --header 'Content-Type: application/json' \
'http://localhost:9200/custom_index/_search' \
-d '{ "query": { "match": { "content": "faq" } } }'
curl -X PUT --header 'Content-Type: application/json' \
'http://localhost:9200/custom_index/_doc/2' \
-d '{ "content": "testing" }'
curl -X POST --header 'Content-Type: application/json' \
'http://localhost:9200/custom_index/_doc/2/_update' \
-d '{ "doc": { "testing": 50000 } }'
curl -X DELETE 'http://localhost:9200/custom_index'
Conclusion
Elasticsearch is a fast, scalable search and analytics engine ideal for eCommerce, log analysis, recommendation engines, and enterprise search. Its speed, flexibility, and advanced search features make it perfect for Magento stores handling large datasets and complex queries.