You are here

public function SearchApiElasticsearchBackend::updateIndex in Elasticsearch Connector 8.5

Same name and namespace in other branches
  1. 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::updateIndex()
  2. 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 390

Class

SearchApiElasticsearchBackend
Elasticsearch Search API Backend definition.

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

Code

public function updateIndex(IndexInterface $index) {
  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_set_message($this
          ->t('The elasticsearch client was not able to create index'), 'error');
      }
    }

    // Update mapping.
    $this
      ->fieldsUpdated($index);
  } catch (ElasticsearchException $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
  }
}