Skip to content

Commit 26d9226

Browse files
committed
Made alias setPrimaryIndex compatible with 1.x elasticsearch client.
1 parent 6b411bf commit 26d9226

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Strategy/AliasStrategy.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function getPrimaryIndex()
5757
*/
5858
public function setPrimaryIndex($name)
5959
{
60+
$this->logger->debug(sprintf('Setting primary index to %s.', $name));
6061
$params = [
6162
'body' => [
6263
'actions' => [
@@ -73,9 +74,15 @@ public function setPrimaryIndex($name)
7374
]
7475
]
7576
]
76-
],
77-
'client' => ['ignore' => 404]
77+
]
7878
];
79-
$this->engine->indices()->updateAliases($params);
79+
try {
80+
$this->engine->indices()->updateAliases($params);
81+
} catch (\Elasticsearch\Common\Exceptions\Missing404Exception $e) {
82+
$this->logger->debug('No aliases matched the pattern. Retrying without the removal of old indices.');
83+
array_shift($params['body']['actions']);
84+
$this->engine->indices()->updateAliases($params);
85+
}
86+
8087
}
8188
}

0 commit comments

Comments
 (0)