Cron jobs failure because of ElasticSearch (which is disabled)

OS: Linux
SuiteCRM: 7.11.2 (Fresh install)
On a shared host (I am unable to configure ElasticSearc as per the manual)

I am getting an error in the SuiteCRM log every minute when cron.php is launched by the scheduler.
There is no error in the PHP/Apache log.

This failure stops the execution of all Scheduler Jobs so therefore it is a big problem!

This is the error:

Tue Feb 26 14:16:01 2019 [2703158][1][FATAL] [ERROR] Failed to index bean to index
Tue Feb 26 14:16:01 2019 [2703158][1][FATAL] [ERROR] SuiteCRM\Search\Exceptions\SearchException: Elasticsearch trying to re-indexing a bean but indexer is disabled in configuration. in /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/lib/Search/ElasticSearch/ElasticSearchHooks.php:121
Stack trace:
#0 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/lib/Search/ElasticSearch/ElasticSearchHooks.php(103): SuiteCRM\Search\ElasticSearch\ElasticSearchHooks->reIndex(Object(SchedulersJob))
#1 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/lib/Search/ElasticSearch/ElasticSearchHooks.php(76): SuiteCRM\Search\ElasticSearch\ElasticSearchHooks->reIndexSafe(Object(SchedulersJob))
#2 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/include/utils/LogicHook.php(272): SuiteCRM\Search\ElasticSearch\ElasticSearchHooks->beanSaved(Object(SchedulersJob), 'after_save', '')
#3 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/include/utils/LogicHook.php(213): LogicHook->process_hooks(Array, 'after_save', '')
#4 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/data/SugarBean.php(3129): LogicHook->call_custom_logic('SchedulersJobs', 'after_save', '')
#5 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/data/SugarBean.php(2442): SugarBean->call_custom_logic('after_save', '')
#6 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/modules/SchedulersJobs/SchedulersJob.php(320): SugarBean->save()
#7 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/modules/SchedulersJobs/SchedulersJob.php(546): SchedulersJob->resolveJob('success')
#8 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/include/SugarQueue/SugarCronJobs.php(191): SchedulersJob->runJob()
#9 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/include/SugarQueue/SugarCronJobs.php(231): SugarCronJobs->executeJob(Object(SchedulersJob))
#10 /var/www/vhosts/website.com/httpdocs/crm.website.net/suitecrm/cron.php(99): SugarCronJobs->runCycle()
#11 {main}

However ElasticSearch is not enabled in Admin:

Search Indexing is set to Basic + Advanced (so why is ElasticSearch trying to do something?)

I don’t see any Scheduler job for ElasticSearch:

Is there a way to stop this from running so that my other Scheduled job can continue execution?

I found this fix in gitHub:
https://github.com/salesagility/SuiteCRM/pull/6986

But it doesn’t seem to be exactly the same as my error message mentions a different file:
lib/Search/ElasticSearch/ElasticSearchHooks.php

So I modified this latter file:

old code:

   /**
     * Callback for save beans.
     *
     * @param SugarBean $bean
     * @param           $event
     * @param           $arguments
     */
    public function beanSaved(SugarBean $bean, $event, $arguments)
    {
        $this->action = 'index';

        $this->reIndexSafe($bean);
    }

with the following code, which now checks if ElasticSearch is enabled:

   /**
     * Callback for save beans.
     *
     * @param SugarBean $bean
     * @param           $event
     * @param           $arguments
     */
    public function beanSaved(SugarBean $bean, $event, $arguments)
    {
        $this->action = 'index';

        if (ElasticSearchIndexer::isEnabled() !== false)
          $this->reIndexSafe($bean);
    }

This has solved my issue but, since I don’t know much or anything about ElasticSearch, I am not sure that this is is the correct solution.

Does anyone have the same problem?

Any comments/solutions/suggestions?

@amariussi your change sounds reasonable, that function is defined inside that same file, so it is only for ElasticSearch, it shouldn’t be a problem to skip executing it.

The only thing we could still explore better is if this can be skipped earlier in the process, for performance reasons. If we can test if Elastic Search is off before calling any Hooks, that would be better, especially in large operations affecting many beans…

1 Like

Thanks Pedro.

I agree with you but I don’t know where to look.

I had a look and I think the Hooks are created by the installer. So they are always there, though you can always do an extension that clears up the array entry (instead of adding to it as we usually do when defining a hook).

But maybe it’s easier to just use your solution, and it’s just a few function calls, no disk activity and no database activity, so the performance hit shouldn’t be too bad.

I will post an issue on gitHub describing my proposed solution and adding a link to this Forum thread.

1 Like

For future reference, this is the fix which should be in 7.11.8

https://github.com/salesagility/SuiteCRM/commit/ca230676e7dcb37b9b681eb9ddd350b8f44dbb3c