You are here

public static function IndexFactory::create in Elasticsearch Connector 8.6

Same name and namespace in other branches
  1. 8.7 src/ElasticSearch/Parameters/Factory/IndexFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\IndexFactory::create()
  2. 8.2 src/ElasticSearch/Parameters/Factory/IndexFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\IndexFactory::create()
  3. 8.5 src/ElasticSearch/Parameters/Factory/IndexFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\IndexFactory::create()

Build parameters required to create an index TODO: Add the timeout option.

Parameters

\Drupal\search_api\IndexInterface $index:

Return value

array

File

src/ElasticSearch/Parameters/Factory/IndexFactory.php, line 58

Class

IndexFactory
Create Elasticsearch Indices.

Namespace

Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory

Code

public static function create(IndexInterface $index) {
  $indexName = static::getIndexName($index);
  $indexConfig = [
    'index' => $indexName,
    'body' => [
      'settings' => [
        'number_of_shards' => $index
          ->getOption('number_of_shards', 5),
        'number_of_replicas' => $index
          ->getOption('number_of_replicas', 1),
      ],
    ],
  ];

  // Allow other modules to alter index config before we create it.
  $dispatcher = \Drupal::service('event_dispatcher');
  $prepareIndexEvent = new PrepareIndexEvent($indexConfig, $indexName);
  $event = $dispatcher
    ->dispatch(PrepareIndexEvent::PREPARE_INDEX, $prepareIndexEvent);
  $indexConfig = $event
    ->getIndexConfig();
  return $indexConfig;
}