You are here

public function SearchApiElasticsearchBackend::fieldsUpdated in Elasticsearch Connector 8.7

Same name and namespace in other branches
  1. 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::fieldsUpdated()
  2. 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::fieldsUpdated()
  3. 8.5 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::fieldsUpdated()
  4. 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::fieldsUpdated()

Create or re-create the given index's field mapping.

Parameters

\Drupal\search_api\IndexInterface $index: Index to update fields for.

Return value

bool TRUE on success, FALSE otherwise.

1 call to SearchApiElasticsearchBackend::fieldsUpdated()
SearchApiElasticsearchBackend::updateIndex in src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php
Notifies the server that an index attached to it has been changed.

File

src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php, line 436

Class

SearchApiElasticsearchBackend
Elasticsearch Search API Backend definition.

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

Code

public function fieldsUpdated(IndexInterface $index) {

  // Do not update read-only indexes.
  if ($index
    ->isReadOnly()) {
    return FALSE;
  }
  try {
    if (!$this->client
      ->indices()
      ->exists($this->indexFactory
      ->index($index))) {
      $this
        ->addIndex($index);
    }
    $response = $this->client
      ->indices()
      ->putMapping($this->indexFactory
      ->mapping($index));
    if (!$this->client
      ->CheckResponseAck($response)) {
      \Drupal::messenger()
        ->addError(t('Cannot create the mapping of the fields!'));
    }
  } catch (\Exception $e) {
    \Drupal::messenger()
      ->addError($e
      ->getMessage());
    return FALSE;
  }
  return TRUE;
}