public function SearchApiElasticsearchBackend::indexItems in Elasticsearch Connector 8.5
Same name and namespace in other branches
- 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::indexItems()
- 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::indexItems()
- 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::indexItems()
- 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::indexItems()
Indexes the specified items.
Parameters
\Drupal\search_api\IndexInterface $index: The search index for which items should be indexed.
\Drupal\search_api\Item\ItemInterface[] $items: An array of items to be indexed, keyed by their item IDs.
Return value
string[] The IDs of all items that were successfully indexed.
Throws
\Drupal\search_api\SearchApiException Thrown if indexing was prevented by a fundamental configuration error.
Overrides BackendSpecificInterface::indexItems
File
- src/
Plugin/ search_api/ backend/ SearchApiElasticsearchBackend.php, line 475
Class
- SearchApiElasticsearchBackend
- Elasticsearch Search API Backend definition.
Namespace
Drupal\elasticsearch_connector\Plugin\search_api\backendCode
public function indexItems(IndexInterface $index, array $items) {
$elastic_type_exists = $this
->doesTypeExists($index);
if (empty($elastic_type_exists) || empty($items)) {
return array();
}
try {
$response = $this->client
->bulk($this->indexFactory
->bulkIndex($index, $items));
// If there were any errors, log them and throw an exception.
if (!empty($response['errors'])) {
foreach ($response['items'] as $item) {
if (!empty($item['index']['status']) && $item['index']['status'] == '400') {
$this->logger
->error('%reason. %caused_by for id: %id', [
'%reason' => $item['index']['error']['reason'],
'%caused_by' => $item['index']['error']['caused_by']['reason'],
'%id' => $item['index']['_id'],
]);
}
}
throw new SearchApiException($this
->t('An error occurred during indexing. Check your watchdog for more information.'));
}
} catch (ElasticsearchException $e) {
drupal_set_message($e
->getMessage(), 'error');
}
return array_keys($items);
}