PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 23, 2022

[FIXED] How to Magento 2 working with ElasticSearch

 August 23, 2022     elasticsearch, full-text-search, magento2     No comments   

Issue

I'm learning Magento 2. I have a project working with ElasticSearch, I don't know how exactly Magento 2 working with ElasticSearch. Could you please tell me how it works. Because I was confused between Sort By of Magento and Sort by Elastic.

  1. How exactly Sort By function work?

    1.1. The Collection of the product was sorted by Magento or ElasticSearch when I have sort by Price or Name?

  2. Does Magento support sort Product Collection using ElasticSearch?

  3. When Sorted by Relevance the product collection was sort by Elastic or Magento?

  4. If Magento doesn't support Sort Attribute using ElasticSearch what should I do to improve that

I have used Magento 2.1.3 & ElasticSearch 2.2 (Magento 2.1 doesn't work with the higher version)

Regards.

Thanks any típs.


Solution

For being short, Magento only support sort by score (relevance) with Elasticsearch for fulltext search.

The other sort options are performed after, during database query.

Indeed, even if a quite lot information are stored in ElasticSearch, Elasticsearch returns only a list of IDs - Score to Magento. Then Magento do a SQL request in order to load all information needed with the sort etc.

In order to sort by score, Magento create a temporary table with the result of ElasticSearch ID - Score to sort the Magento product collection.

But you can extend the module to add your complete feature.

So for answer your questions :

  • The Collection of the product was sorted by Magento or ElasticSearch when I have sort by Price or Name?

The sort is done on Magento side

  • Does Magento support sort Product Collection using ElasticSearch?

It doesnt support the native Elasticsearch sort feature. But can be extended. But the final result is ok.

  • When Sorted by Relevance the product collection was sort by Elastic or Magento?

The relevance (score) is performed by ElasticSearch and then stored to a temporary table and use in a JOIN SQL request.

  • If Magento doesn't support Sort Attribute using ElasticSearch what should I do to improve that

Extend the ElasticSearch SearchAdapter. I can help you on that. You need to build the sort values in the query based on your request. And then manage the sort values in the response.



Answered By - Franck Garnier
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing