Skip to content

Commit

Permalink
check if index exists before deleting it
Browse files Browse the repository at this point in the history
  • Loading branch information
limenet committed Dec 16, 2022
1 parent 53ce5e5 commit 5ed4d82
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Jobs/SetupIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function migrate(ElasticaClient $elastica): void
try {
$response = $elastica->getClient()->request(sprintf('_alias/%s', $this->indexConfig->getName()));
} catch (ClientException|ConnectionException|ResponseException) {
if (count($index->getAliases()) === 0) {
if ($index->exists() && count($index->getAliases()) === 0) {
$index->delete();
}

Expand All @@ -58,7 +58,9 @@ private function migrate(ElasticaClient $elastica): void
return;
}

$index->delete();
if ($index->exists()) {
$index->delete();
}
}

private function cleanup(ElasticaClient $elastica): void
Expand Down

0 comments on commit 5ed4d82

Please sign in to comment.