public static function IndexFactory::bulkIndex in Elasticsearch Connector 8.2
Same name and namespace in other branches
- 8.7 src/ElasticSearch/Parameters/Factory/IndexFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\IndexFactory::bulkIndex()
- 8.5 src/ElasticSearch/Parameters/Factory/IndexFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\IndexFactory::bulkIndex()
- 8.6 src/ElasticSearch/Parameters/Factory/IndexFactory.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\IndexFactory::bulkIndex()
Build parameters to bulk delete indexes.
Parameters
\Drupal\search_api\IndexInterface $index:
\Drupal\search_api\Item\ItemInterface[] $items:
Return value
array
1 call to IndexFactory::bulkIndex()
- SearchApiElasticsearchBackend::indexItems in src/
Plugin/ search_api/ backend/ SearchApiElasticsearchBackend.php - Indexes the specified items.
File
- src/
ElasticSearch/ Parameters/ Factory/ IndexFactory.php, line 91
Class
- IndexFactory
- Class IndexFactory.
Namespace
Drupal\elasticsearch_connector\ElasticSearch\Parameters\FactoryCode
public static function bulkIndex(IndexInterface $index, array $items) {
$params = IndexFactory::index($index, TRUE);
foreach ($items as $id => $item) {
$data = [
'id' => $id,
];
/** @var FieldInterface $field */
foreach ($item as $name => $field) {
$field_type = $field
->getType();
if (!empty($field
->getValues())) {
$values = array();
foreach ($field
->getValues() as $value) {
switch ($field_type) {
case 'string':
$values[] = (string) $value;
break;
case 'text':
$values[] = $value
->toText();
break;
default:
$values[] = $value;
}
}
$data[$field
->getFieldIdentifier()] = $values;
}
}
$params['body'][] = [
'index' => [
'_id' => $data['id'],
],
];
$params['body'][] = $data;
}
return $params;
}