public function deleteAllIndexItems(IndexInterface $index, $datasource_id = NULL) {
    $this->removeIndex($index);
    $this->addIndex($index);
  }

Here it would be nice to preserve the index setting, like if you configured a custom tokenizer for the index or stopwords directly in ElasticSearch, you'd not like to lose it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Aron Novak created an issue. See original summary.

Aron Novak’s picture

Status: Active » Needs review
FileSize
2.4 KB
sokru’s picture

Status: Needs review » Needs work

Code is good and works like advertised, but I'm setting the status Needs work because this will override any index settings made via elasticsearch_connector.prepare_index EventSubscriber. E.g. if one uses something like https://git.drupalcode.org/project/elasticsearch_connector_autocomp/-/bl... to update the index settings, these will be overwritten because $this->setSettings comes after $this->addIndex().

I think this feature should be optional and one could set it on/off from Index options /admin/config/search/search-api/index/{INDEX_NAME}/edit.

bburg’s picture

The patch in #2 still effectively deletes the index and re-creates it. This becomes an issue if you are using prefixes to share indexes between dev/live environments, where using the "Clear all indexed data" in one environment will clear the index in all environments that share it.

Is there anyway to just delete the indexed items without deleting and recreating the entire index?

yonailo’s picture

In my opinion no ElasticSearch configuration should be added outside of Drupal. If you use 'elasticsearch_connector.prepare_index' configuration will be preserved.