Smile-SA / elasticsuite

Smile ElasticSuite - Magento 2 merchandising and search engine built on ElasticSearch
https://elasticsuite.io
Open Software License 3.0
763 stars 342 forks source link

Empty category issue #3391

Open Nuranto opened 2 months ago

Nuranto commented 2 months ago

Magento Version : 2.4.7-p2

ElasticSuite Version : 2.11.8.3

Steps to reproduce

  1. Simulate a query exception in src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Adapter.php : add line $searchResponse = []; before return
  2. Load a category page

Expected result

  1. An error page is diplayed (or non-cacheable empty category page)

Actual result

  1. Cacheable empty category

Additional informations

The case where an exception is thrown and $searchResponse gets empty is very very rare in our case. But when it happens, it may be put in cache by Varnish, which causes empty categories displayed to customers for hours...

Also the exception logging method ($this->logger->error($e->getMessage());) is not very handy. A specific logfile and usage of $this->logger->critical($e); would be more powerfull for debugging.

Note : jfyi there's a similar issue on Adobe's adapter : https://github.com/magento/magento2/issues/38284

romainruaud commented 2 months ago

Hi @Nuranto

I think that, as a first step, we'll add something onto this line : https://github.com/Smile-SA/elasticsuite/blob/2.11.x/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Adapter.php#L84

Most probably, we'll add to the HTTP context some variable, like "X-Search-Failure". This should allow you to set these pages as not-cacheable with a plugin on the HTTP context later on.

Would this fit ?

Regards

Nuranto commented 2 months ago

Hi @romainruaud ,

Thank you for your answer,

We already fixed the caching issue by throwing the exception when it happens. We prefer a temporary error on our category page than a long-term empty category. Your solution would work too, but I think a more "out of the box" solution would be better.

And it works, we just got alerted that the issue occured again. Here is the exception that causes the issue :

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: empty String",
        "index_uuid": "---",
        "index": "magento2_default_catalog_product_20240929_232103"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "magento2_default_catalog_product_20240929_232103",
        "node": "---",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: empty String",
          "index_uuid": "---",
          "index": "magento2_default_catalog_product_20240929_232103",
          "caused_by": {
            "type": "number_format_exception",
            "reason": "empty String"
          }
        }
      }
    ]
  },
  "status": 400
}

After cleaning magento cache (bin/magento c:f), the error disappeared.

I don't know where to search here, any ideas on how to debug ? How a query can be empty, and why purging cache solves that ?