Hikmadh Commerce| Ecommerce Development Consulting | Magento Development and Consulting Service

ElasticSearch Implementation Magento 2

Elastic Search

Elasticsearch is a very robust and extremely extensible wide-ranged search engine which is been used by large-quantity sites. When you implement Elasticsearch in your Magento 2 Store it includes search recommendations and suggestions.

Elasticsearch has many advantages, it shows immediate search result with all the necessary searches autocomplete and also evaluate all the equivalent keywords. It also provides the feature of redirecting a user to the home page if one matching result is found.

Magento Elastic Search Architecture

 

Feature of Elasticsearch

1) ElasticSearch provides tools for correcting typing errors,ElasticSearch provides two advanced tools for correcting typing errors: Fuzzy Search and Phonetic Search.

Fuzzy Search: The more the words are similar, the higher chance Elastic Search will suggest that product. For example, when customers input “sweetshirt”, Fuzzy function will detect the most relevant word to it and suggest “sweatshirt” items instead of other results like “t-shirt”.

Phonetic Search: allows suggesting products with the most same pronunciation. If typing “llaguing” into the search box, the results shown are likely “leggings” items since they are pronounced almost similarly.

2) Provide Alternatives If You Don’t Have Exact Match to A Customer Query

3) Full-text and full-website multilingual search

4) Add alternate search terms and words to ignore

5) Full Control Over Sorting of Your Search Results

6) ElasticSearch allow searching by synonyms

ElasticSearch is integrated with a customizable synonym system which helps customers search by the similar-meaning words. “Man” – ”Men”, “Denim” – “Blue” are examples for synonyms most used by shoppers.

Auto-detect and ignore stopwords In addition, this module helps to quickly detect specific stopwords such as “and, or, for, to, by, etc.” in the search queries then ignore them at a certain level. As a result, ElasticSearch provides a more accurate answer with an incredible speed.

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

Creating Custom Index on ES

This section describes about creating Elastic Search Index using our custom tables.

Creating Custom Index include two xml file and indexer PHP file to details about field to index.

1). Indexer.xml

This file tells to magento indexer about our custom name of indexer and PHP file for creating index

2). mview.xml

This file mview means merchandizing view, its indicate/tells indexer on update mode whenever change happened in custom table ready for indexing/updating the index by its id.

3). Indexer PHP File

This file create instance for ES and create the custom index and post the rows of table for indexing

 

Custom Search on ES

We can create instance of Elastic Search client library to search by specific search on our created custom index. We need to specify following parameters while searching on index

  1.  Name of our index
  2.  Type of index
  3.  Query with search type and fields to be searched
  4.  Size of the resultant counts to be displayed

Elastic Search Rest APIs Commands

Here we show some of the most common ElasticSearch commands using curl. ElasticSearch is sometimes complicated. So here we make it simple

 

1)list all indexes

 

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

2) list all docs in index

 

curl -X GET ‘http://localhost:9200/custom_index/_search’

3) query using URL parameters s

 

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

4) Query with JSON

 

curl -X GET –header ‘Content-Type: application/json’ http://localhost:9200/custom_index/_search -d ‘{ “query” : { “match” : { “content”: “faq” } } }’

5) Add Data

 

curl -X PUT –header ‘Content-Type: application/json’ http://localhost:9200/custom_index/_doc/2 -d ‘ { “content”: “testing” }’

6) Update Doc

 

curl -X POST –header ‘Content-Type: application/json’ http://localhost:9200/custom_index/_doc/2/_update -d ‘{ “doc” : { “testing”: 50000} }’

7) delete index

 

curl -X DELETE ‘http://localhost:9200/custom_index’

Conclusion

Overall, Elasticsearch is a highly versatile and scalable search and analytics engine, suitable for a wide range of applications such as log analysis, e-commerce, recommendation systems, and enterprise search. Its combination of speed, scalability, and flexibility makes it a popular choice for organizations dealing with large volumes of data and complex search requirements.