Skip to content

Commit 4c6afc2

Browse files
author
Roman Hanin
committed
B2B-1832: Error when reindex Catalog Search index during the snapshot of elasticsearch
1 parent 71ad358 commit 4c6afc2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,23 @@ public function cleanIndex($storeId, $mappedIndexerId)
239239
// prepare new index name and increase version
240240
$indexPattern = $this->indexNameResolver->getIndexPattern($storeId, $mappedIndexerId);
241241
$version = (int)(str_replace($indexPattern, '', $indexName));
242-
$newIndexName = $indexPattern . (++$version);
243242

244-
// remove index if already exists
245-
if ($this->client->indexExists($newIndexName)) {
243+
// compatibility with snapshotting collision
244+
$deleteQueue = [];
245+
do {
246+
$newIndexName = $indexPattern . (++$version);
247+
if ($this->client->indexExists($newIndexName)) {
248+
$deleteQueue []= $newIndexName;
249+
$indexExists = true;
250+
} else {
251+
$indexExists = false;
252+
}
253+
} while ($indexExists);
254+
255+
foreach ($deleteQueue as $indexToDelete) {
256+
// remove index if already exists
246257
try {
247-
$this->client->deleteIndex($newIndexName);
258+
$this->client->deleteIndex($indexToDelete);
248259
} catch (\Exception $e) {
249260
$this->logger->critical($e);
250261
}

0 commit comments

Comments
 (0)