Skip to content

Commit 67adb26

Browse files
committed
Added method to override the bulk request size in ProviderInterface
1 parent bd50df6 commit 67adb26

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Document/Provider/AbstractProvider.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
abstract class AbstractProvider implements ProviderInterface
1111
{
12-
1312
/**
1413
* @var string The type the provider is for
1514
*/
@@ -48,4 +47,15 @@ abstract public function getDocuments();
4847
* @return DocumentInterface|array
4948
*/
5049
abstract public function getDocument($id);
50+
51+
/**
52+
* Returns the number of Elasticsearch documents to persist in a single bulk request
53+
* If null is returned, the 'bulk_batch_size' of the Connection will be used
54+
*
55+
* @return int|null
56+
*/
57+
public function getPersistRequestBatchSize() : ?int
58+
{
59+
return null;
60+
}
5161
}

Document/Provider/ProviderInterface.php

+8
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ public function getDocuments();
3434
* @return DocumentInterface|array
3535
*/
3636
public function getDocument($id);
37+
38+
/**
39+
* Returns the number of Elasticsearch documents to persist in a single bulk request
40+
* If null is returned, the 'bulk_batch_size' of the Connection will be used
41+
*
42+
* @return int|null
43+
*/
44+
public function getPersistRequestBatchSize() : ?int;
3745
}

Manager/IndexManager.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -687,15 +687,15 @@ protected function createNewIndexWithUniqueName()
687687
*/
688688
protected function copyDataToNewIndex(string $newIndex, string $oldIndex)
689689
{
690-
$batchSize = $this->connection->getConnectionSettings()['bulk_batch_size'];
691-
692690
// Make sure we don't autocommit on every item in the bulk request
693691
$autocommit = $this->getConnection()->isAutocommit();
694692
$this->getConnection()->setAutocommit(false);
695693

696-
$typeDataProvider = $this->getDataProvider();
694+
$indexDataProvider = $this->getDataProvider();
695+
$batchSize = $indexDataProvider->getPersistRequestBatchSize() ?? $this->connection->getConnectionSettings()['bulk_batch_size'];
696+
697697
$i = 1;
698-
foreach ($typeDataProvider->getDocuments() as $document) {
698+
foreach ($indexDataProvider->getDocuments() as $document) {
699699
// Temporarily override the write alias with the new physical index name, so rebuilding only happens in the new index
700700
$originalWriteAlias = $this->writeAlias;
701701
$this->setWriteAlias($newIndex);

0 commit comments

Comments
 (0)