public function SearchApiElasticsearchBackend::updateIndex in Elasticsearch Connector 8.7
Same name and namespace in other branches
- 8.5 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::updateIndex()
- 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::updateIndex()
Notifies the server that an index attached to it has been changed.
If any user action is necessary as a result of this, the method should set a message to notify the user.
Parameters
\Drupal\search_api\IndexInterface $index: The updated index.
Throws
\Drupal\search_api\SearchApiException Thrown if an error occurred while reacting to the change.
Overrides BackendPluginBase::updateIndex
1 call to SearchApiElasticsearchBackend::updateIndex()
- SearchApiElasticsearchBackend::addIndex in src/
Plugin/ search_api/ backend/ SearchApiElasticsearchBackend.php - Adds a new index to this server.
File
- src/
Plugin/ search_api/ backend/ SearchApiElasticsearchBackend.php, line 403
Class
- SearchApiElasticsearchBackend
- Elasticsearch Search API Backend definition.
Namespace
Drupal\elasticsearch_connector\Plugin\search_api\backendCode
public function updateIndex(IndexInterface $index) {
// Do not update read-only indexes.
if ($index
->isReadOnly()) {
return;
}
try {
if (!$this->client
->indices()
->exists($this->indexFactory
->index($index))) {
$response = $this->client
->indices()
->create($this->indexFactory
->create($index));
if (!$this->client
->CheckResponseAck($response)) {
\Drupal::messenger()
->addError($this
->t('The elasticsearch client was not able to create index'));
}
}
// Update mapping.
$this
->fieldsUpdated($index);
} catch (ElasticsearchException $e) {
\Drupal::messenger()
->addError($e
->getMessage());
}
}