Problem/Motivation

Elastic Search backend instance breaks Search API Server form when more than 1 type of search backend is active

I am getting an issue where you have an elasticsearch index and a second type of search like solr.

When you acess the Edit Server form for the other type of search index (eg Solr) search api, the webpage crashes with the following error:

Drupal\search_api\SearchApiException: Cannot load the Elasticsearch cluster for your index. in Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend->__construct() (line 205 of modules/contrib/elasticsearch_connector/src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php).

`SearchApiElasticsearchBackend` does not check to see if it is the active search backend instance for the page before throwing error.

Steps to reproduce

1. Create a solr search index
2. Create an elastic search index
3. Attempt to edit the solr search server
4. Website crashes

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RichardGaunt created an issue. See original summary.

RichardGaunt’s picture

Version: 7.x-5.0-alpha1 » 8.x-7.x-dev
RichardGaunt’s picture

Added patch that checks to see if it is the active backend before throwing exception.

RichardGaunt’s picture

Minor change

RichardGaunt’s picture

Priority: Normal » Major
FileSize
1.85 KB

Updated for change in settings structure and updated issue priority to major as it blocks viewing non-elasticsearch server pages.

RichardGaunt’s picture

Improved the patch, early exit from the `SearchApiElasticsearchBackend::_construct` if it is not active backend.

hktang’s picture

With the patch from #6, I can open the form, but I assume there will be a form to enter ElasticSearch server details. That didn't show up.

When I click "Save", the same error appears. Here's the debugging message:

"
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /admin/config/search/search-api/add-server?ajax_form=1
StatusText: error
ResponseText: The website encountered an unexpected error. Please try again later.Drupal\search_api\SearchApiException: Cannot load the Elasticsearch cluster for your index. in Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend->__construct() (line 210 of modules/contrib/elasticsearch_connector/src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php). Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::create(Object, Array, 'elasticsearch', Array) (Line: 21)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('elasticsearch', Array) (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance('elasticsearch', Array) (Line: 148)
Drupal\search_api\Form\ServerForm->buildEntityForm(Array, Object, Object) (Line: 85)
Drupal\search_api\Form\ServerForm->form(Array, Object) (Line: 107)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('search_api_server_form', Object) (Line: 375)
Drupal\Core\Form\FormBuilder->rebuildForm('search_api_server_form', Object, Array) (Line: 633)
Drupal\Core\Form\FormBuilder->processForm('search_api_server_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
"