Magento 2 + ElasticSearch Not Showing Search Results

catalogsearchelasticsearchmagento2

Before I enabled ElasticSearch the search bar would give me a list of categories, products, and blog posts that matched. And when I hit enter the search results page would contain the matching products.

After I enabled ElasticSearch the search term suggestions show, but the results page contains no products. Oddly if I do an "advanced search" (/catalogsearch/advanced) I do get the results I would expect.

I'm using Magento 2.3.4 with ElasticSearch 6.8.7.

I've done the following on my test server to try to diagnose the problem:

  • Configured and setup ElasticSearch.
  • Configured Magento according to the Magento documentation, I get the "Successful! Test Again?" button
  • Run bin/magento indexer:reindex
  • Installed kibana to make sure I can see and search the data in ElasticSearch, I can.
  • Switched to the luma theme to eliminate the theme as the issue.
  • Checked log files for new error message (error, exception, system). No messages were generated doing searches besides access log messages.

If anyone has any suggestions or advice I'd greatly appreciate it.

Thanks,
Brian

Best Answer

Give a try below to check atleast if ElasticSearch returns some results or not?

File: Check\Es\etc\di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Elasticsearch\SearchAdapter\ResponseFactory">
      <plugin name="ESChecker::willReturnsDocuments" type="Check\Es\Plugin\ESResponseCheck" sortOrder="1" disabled="false" />
    </type>
</config>

File: Check\Es\Plugin\ESResponseCheck.php

<?php
namespace Check\Es\Plugin;

use Magento\Elasticsearch\SearchAdapter;
use Psr\Log\LoggerInterface;


class ESResponseCheck
{

    protected $logger;

    public function __construct(
        LoggerInterface $logger        
    ) {
        $this->logger = $logger;

    }

    public function beforeCreate(\Magento\Elasticsearch\SearchAdapter\ResponseFactory $subject, $result)
    {
       if(!is_array($result) || empty($result)) return false;
       foreach ($result['documents'] as $rawDocument) {
            $this->logger->debug('ELASTIC_SEARCH_DEBUG_CODE',$rawDocument);   
       }            

    }
}

Clear the cache and catalog search reindexing

Perform any search terms and check var/debug.log file found in the Magento root directory.

In the debug.log file look for the product IDs returns from the ElasticSearch.

Also, check below URL for further info - https://magento.stackexchange.com/a/285358/34579