Elasticsuite: Disable indexing on Installation

Created on 12 Dec 2019  路  4Comments  路  Source: Smile-SA/elasticsuite

Preconditions


Magento Version : 2.3.2


ElasticSuite Version : 2.8.2


Environment : Production


Third party modules :

Steps to reproduce

  1. Setup:install --(install params)
    2.
    3.

Expected result

  1. Magento should install

Actual result


1.

PHP Fatal error:  Uncaught Error: Cannot instantiate interface Smile\ElasticsuiteCore\Api\Client\ClientInterface in /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:116
Stack trace:
#0 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(108): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Smile\\Elasticsu...', Array)
#1 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(150): Magento\Framework\ObjectManager\Factory\Compiled->create('Smile\\Elasticsu...')
#2 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(79): Magento\Framework\ObjectManager\Factory\Compiled->get('Smile\\Elasticsu...')
#3 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(150): Magento\Framework\ObjectManager\Factory\Compiled->create('Smile\\Elasticsu...')
#4 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Compiled.php(79): Magento\Framework\ObjectManager\Factory\Compiled->get('Smile\\Elasticsu...')
# in /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 116

To solve this, please don't index Magento 2 before the indexers are available. I've commented out the Setup code that indexes, and the install went through as expected.

This should through an error before installation, or log and continue. Not fail an installation half way through.

To solve:
Change 2 files:
and add a try cactch to the reindexAll function, so that if nodes aren't found, the installation continues:

$this->getIndexer('elasticsuite_categories_fulltext')->reindexAll();
and
$this->getIndexer('elasticsuite_thesaurus')->reindexAll();

vi vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Setup/InstallData.php

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     *
     * Installs Data for the module :
     *  - Create attribute on category to enable/disable name indexation for search
     *  - Update is anchor attribute (hidden frontend input, null source model, enabled by default).
     *
     * @param ModuleDataSetupInterface $setup   The setup interface
     * @param ModuleContextInterface   $context The module Context
     *
     * @return void
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)                                                                                        
   {                                                                                                                                                                                    
   $setup->startSetup();                                                                                                                                                            
   $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);                                                                                                                                                                                                                                                                                                  
   $this->catalogSetup->addCategoryNameSearchAttribute($eavSetup);                                                                                                                  
   $this->catalogSetup->updateCategoryIsAnchorAttribute($eavSetup);                                                                                                                 
   $this->catalogSetup->updateDefaultValuesForNameAttributes($eavSetup);                                                                                                            
   $this->catalogSetup->updateCategorySearchableAttributes($eavSetup);                                                                                                              
   $this->catalogSetup->updateImageAttribute($eavSetup);          
   try{                                                                                                                                                                                                                                                                                                   
       $this->getIndexer('elasticsuite_categories_fulltext')->reindexAll();                                                                                                                                                                                                                                                                                            
   }
   catch(Exception $e){
      //todo: handle exception and not catch general Exception
   }
   $setup->endSetup();                                                                                                                                                          }

vi vendor/smile/elasticsuite/src/module-elasticsuite-thesaurus/Setup/InstallData.php

Change install function to:

    /**
     * Installs module data.
     * Rebuild Thesaurus index.
     *                                                                                                                                                                                * @SuppressWarnings(PHPMD.UnusedFormalParameter)                                                                                                                                 *                                                                                                                                                                                * @param ModuleDataSetupInterface $setup   Setup Interface                                                                                                                       * @param ModuleContextInterface   $context Module Context Interface                                                                                                              *                                                                                                                                                                                * @return void                                                                                                                                                                   */                                                                                                                                                                              public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)                                                                                        {        

   try{                                                                                                                                                                            

      $this->getIndexer('elasticsuite_thesaurus')->reindexAll();                                                                                                                 

   }
   catch(Exception $e){
   //todo: change this to a elastic search node not found exception
   }
}
wontfix

All 4 comments

Magento does trigger himself a reindexing of the catalogsearch_fulltext index : https://github.com/magento/magento2/blob/2.3/app/code/Magento/CatalogSearch/Setup/Patch/Data/SetInitialSearchWeightForAttributes.php#L63

So, this should fail too in case the node is not found.

So, I suspect that you are running the setup:install command without properly setting the Elasticsearch settings :

https://github.com/Smile-SA/elasticsuite/wiki/ModuleInstall#magento-is-not-installed-yet-

The issue isn't whether the index runs; it's that it runs regardless of whether you've specified the install parameter. Once the module is installed, it makes the codebase required to have an elastic search server.

We have developers that would like to develop something out on thier machines, but then are required to install elastic search to dev on that codebase, even if the change has nothing to do with search.

Yes, Search Engine server is part of the E-Commerce application.

If you want to have good practices, your development environment should be as closest as possible to the production environment.

So the development environment should have a running Search Server. It's like having a running MySQL server, it's part of the application and therefore mandatory.

It's very easy to have a complete stack running gracefully (especially with tooling like docker-compose).

Regards

True, but if it's unconfigured, it shouldn't conduct an index, or even try. If you leave RabbitMQ unconfigured, you don't break the installation or configuration of Magento.

Once the module is installed, there is no way to disable it even if you wanted to.

There are plently of reasons to develop a module with random configuration settings, sometimes, with elastic search enabled, sometimes with the mysql full text enabled. With your options, you're preventing the later.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShirishRam picture ShirishRam  路  3Comments

wintermute-84 picture wintermute-84  路  4Comments

DanieliMi picture DanieliMi  路  5Comments

surendiranganesan picture surendiranganesan  路  3Comments

mokadev picture mokadev  路  3Comments