Newer
Older
<?php
namespace IQDEV\ElasticSearch\Indexer;
use Elastic\Elasticsearch\Client;
use IQDEV\ElasticSearch\Configuration;
Client $esClient,
Configuration $configuration,
LoggerInterface $logger
)
{
$this->helper = new EsHelperEndpoint($esClient, $configuration, $logger);
$this->helper->create();
if ($indexProvider->getBatchSize() !== null && $indexProvider->getBatchSize() > 0) {
$counter = 0;
$params = ['body' => []];
foreach ($indexProvider->get() as $index) {
if ($index instanceof DeleteIndex) {
if (!empty($params['body'])) {
$this->esClient->bulk($params);
$params = ['body' => []];
$counter = 0;
}
$this->esClient->delete($index->es());
continue;
}
if ($index instanceof UpdateIndex) {
if (!empty($params['body'])) {
$this->esClient->bulk($params);
$params = ['body' => []];
$counter = 0;
}
$this->esClient->update($index->es());
continue;
}
if (!$index instanceof BulkIndex) {
continue;
}
$esIndex = $index->es();
foreach ($esIndex as $indexItem) {
$params['body'][] = $indexItem;
}
if (++$counter >= $indexProvider->getBatchSize()) {
$this->esClient->bulk($params);
$params = ['body' => []];
$counter = 0;
}
if (!empty($params['body'])) {
$this->esClient->bulk($params);
}
} else {
foreach ($indexProvider->get() as $index) {
if ($index instanceof DeleteIndex) {
$this->esClient->delete($index->es());
continue;
}
if ($index instanceof AddIndex) {
$this->esClient->index($index->es());
if ($index instanceof UpdateIndex) {
$this->esClient->update($index->es());
continue;
}