Magento 2 如何与 ElasticSearch 一起工作

How to Magento 2 working with ElasticSearch

我正在学习 Magento 2。我有一个使用 ElasticSearch 的项目,我不知道 Magento 2 如何与 ElasticSearch 一起使用。你能告诉我它是如何工作的吗?因为我对 Magento 的 Sort By 和 Elastic 的 Sort 感到困惑。

  1. “排序依据”功能究竟是如何工作的?

    1.1。当我按价格或名称排序时,产品的集合是由 Magento 或 ElasticSearch 排序的?

  2. Magento 是否支持使用 ElasticSearch 对产品集合进行排序?

  3. 当按相关性排序时,产品集合按 Elastic 或 Magento 排序?

  4. 如果 Magento 不支持使用 ElasticSearch 的排序属性,我应该怎么做才能改进

我用过 Magento 2.1.3 和 ElasticSearch 2.2(Magento 2.1 不适用于更高版本)

问候。

谢谢大家ps。

简而言之,Magento 仅支持使用 Elasticsearch 进行全文搜索时按分数(相关性)排序。

其他排序选项在数据库查询期间执行。

事实上,即使相当多的信息存储在 ElasticSearch 中,Elasticsearch returns 也只是一个 ID 列表 - 对 Magento 进行评分。然后 Magento 执行 SQL 请求以加载排序等所需的所有信息

为了按分数排序,Magento 使用 ElasticSearch ID - Score 的结果创建一个临时 table 来对 Magento 产品集合进行排序。

但是您可以扩展该模块以添加完整的功能。

所以回答你的问题:

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

排序在 Magento 端完成

  • Does Magento support sort Product Collection using ElasticSearch?

它不支持原生的 Elasticsearch 排序功能。但可以延长。不过最后的结果还是可以的

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

相关性(分数)由 ElasticSearch 执行,然后存储到临时 table 并在 JOIN SQL 请求中使用。

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

扩展 ElasticSearch SearchAdapter。我可以帮你。您需要根据您的请求在查询中构建排序值。然后管理响应中的排序值。