Skip to content

Commit

Permalink
Create indices on update if they don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jraddaoui committed Dec 4, 2024
1 parent 945e8c0 commit 0efd43b
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@ public function populate($options = [])
$className = 'arElasticSearch'.$camelizedTypeName;
$indexName = 'Qubit'.$camelizedTypeName;

// If not updating, recreate index.
if (!$update) {
$this->recreateIndex($indexName, $indexProperties);
}
$this->recreateIndex($indexName, $indexProperties, $update);

$class = new $className();
$class->setTimer($timer);
Expand Down Expand Up @@ -519,10 +516,15 @@ private function initialize()
}
}

private function recreateIndex($indexName, $indexProperties)
private function recreateIndex($indexName, $indexProperties, $update)
{
$index = $this->index->getIndex($indexName);

// No need to recreate updating an existing index.
if ($update && $index->exists()) {
return;
}

try {
$index->delete();
} catch (\Elastica\Exception\ResponseException $e) {
Expand Down

0 comments on commit 0efd43b

Please sign in to comment.