When site has also other search backend than Elasticsearch, adding or clearing elasticsearch index, will provide a fatal error
"Error: Call to undefined method Drupal\search_api_db\Plugin\search_api\backend\Database::getCluster() in Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\IndexFactory::getIndexName() (line 236 of /docroot/modules/contrib/elasticsearch_connector/src/ElasticSearch/Parameters/Factory/IndexFactory.php)"

This is because getIndexName() on src/ElasticSearch/Parameters/Factory/IndexFactory doesn't check if the backend is SearchApiElasticsearchBackend.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Roderik de Langen created an issue. See original summary.

littlepixiez’s picture

I have the same issue, but the fatal error is causing SearchAPI db tables to not be built when I change from an Elasticsearch backend to a DB backend for my indexes.

I've attached a patch to my solution - hope it's the right approach, I've just checked the backend is an instance of a "SearchApiElasticsearchBackend", and then if it isn't defaulted the prefix and suffix to a blank string as these are this-module-specific. Although this IS the function to return the Elasticsearch index name, but obviously it's no longer an Elasticsearch backend but is running the function anyway, so not sure what is best to return in this scenario - maybe the real issue is it's still calling the function after the server type has been changed and shouldn't be?

Either way, this patch helps get over the fatal error, and enables me to switch the backend server of the index without losing/breaking any functionality from either module from what I've tested.

littlepixiez’s picture

Assigned: Unassigned » littlepixiez
Status: Active » Needs review

sokru made their first commit to this issue’s fork.

sokru’s picture

Assigned: littlepixiez » Unassigned

Thanks littlepixiez for your work. Based on your work I simplified the code a bit.
Feel free to reassign yourself in case you want to review the merge request.

sokru’s picture

Issue summary: View changes

  • sokru committed 34b2b456 on 8.x-7.x
    Issue #3153850 by sokru, littlepixiez, Roderik de Langen, IT-Cru: Make...

sokru credited IT-Cru.

sokru’s picture

Status: Needs review » Fixed

Crediting @IT-Cru for testing and reporting on #elasticsearch on drupal.org's Slack.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.