3

I am using Magento's latest community version Magento 2.3.3. I am very new to ElasticSearch. I want to integrate Elasticsearch with Magento, So I took reference from here https://www.tigren.com/magento-2-elasticsearch/ and install Elasticsearch on the localhost.

enter image description here

enter image description here

According to my screenshots, I think, I set up elasticsearch successfully on my local machine but unfortunately, I can't see better search result on the frontend (I mean quick result). On the frontend side, it still takes lots of time for showing results.

Any idea where I am wrong?

and How can I check on frontend elastic search working or not?

5

To check the ElasticSearch on the storefront working or not. Below plugin may help you.

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="check_es_call" type="\Check\Es\Plugin\ESResponseCheck" sortOrder="1" disabled="false" />
    </type>
</config>

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);   
       }            

    }       

}

You can also install Kibana or Logstash monitoring tool for ElasticSearch.

3
  • 1
    I used your above code and get the below logs: [2019-12-26 15:49:57] main.DEBUG: ELASTIC_SEARCH_DEBUG_CODE {"_index":"magento2_product_1_v5","_type":"document","_id":"180","_score":51.224762} [] [2019-12-26 15:49:57] main.DEBUG: ELASTIC_SEARCH_DEBUG_CODE {"_index":"magento2_product_1_v5","_type":"document","_id":"84","_score":44.61884} [] [2019-12-26 15:49:57] main.DEBUG: ELASTIC_SEARCH_DEBUG_CODE {"_index":"magento2_product_1_v5","_type":"document","_id":"260","_score":44.060844} [] Is ElasticSarch working on my store? – Balwant Singh Dec 26 '19 at 15:53
  • yes, absolutely it is working.. That means ElasticSearch is working on the storefront. – sandip Dec 26 '19 at 16:17
  • 1
    thanks for the help. Happy Coding...!!! – Balwant Singh Dec 26 '19 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.