diff --git a/Document/Provider/AbstractProvider.php b/Document/Provider/AbstractProvider.php index 25189fe..4e6b9ff 100644 --- a/Document/Provider/AbstractProvider.php +++ b/Document/Provider/AbstractProvider.php @@ -9,7 +9,6 @@ */ abstract class AbstractProvider implements ProviderInterface { - /** * @var string The type the provider is for */ @@ -48,4 +47,15 @@ abstract public function getDocuments(); * @return DocumentInterface|array */ abstract public function getDocument($id); + + /** + * Returns the number of Elasticsearch documents to persist in a single bulk request + * If null is returned, the 'bulk_batch_size' of the Connection will be used + * + * @return int|null + */ + public function getPersistRequestBatchSize() : ?int + { + return null; + } } diff --git a/Document/Provider/ProviderInterface.php b/Document/Provider/ProviderInterface.php index 5f09947..56d650d 100644 --- a/Document/Provider/ProviderInterface.php +++ b/Document/Provider/ProviderInterface.php @@ -34,4 +34,12 @@ public function getDocuments(); * @return DocumentInterface|array */ public function getDocument($id); + + /** + * Returns the number of Elasticsearch documents to persist in a single bulk request + * If null is returned, the 'bulk_batch_size' of the Connection will be used + * + * @return int|null + */ + public function getPersistRequestBatchSize() : ?int; } diff --git a/Manager/IndexManager.php b/Manager/IndexManager.php index 786db20..44ca270 100644 --- a/Manager/IndexManager.php +++ b/Manager/IndexManager.php @@ -687,15 +687,15 @@ protected function createNewIndexWithUniqueName() */ protected function copyDataToNewIndex(string $newIndex, string $oldIndex) { - $batchSize = $this->connection->getConnectionSettings()['bulk_batch_size']; - // Make sure we don't autocommit on every item in the bulk request $autocommit = $this->getConnection()->isAutocommit(); $this->getConnection()->setAutocommit(false); - $typeDataProvider = $this->getDataProvider(); + $indexDataProvider = $this->getDataProvider(); + $batchSize = $indexDataProvider->getPersistRequestBatchSize() ?? $this->connection->getConnectionSettings()['bulk_batch_size']; + $i = 1; - foreach ($typeDataProvider->getDocuments() as $document) { + foreach ($indexDataProvider->getDocuments() as $document) { // Temporarily override the write alias with the new physical index name, so rebuilding only happens in the new index $originalWriteAlias = $this->writeAlias; $this->setWriteAlias($newIndex);