public getIndicesWithAlias ( string $alias ) : array | |
||
$alias | string | Alias name |
return | array | |
List of Elastica\Index |
public function getIndicesWithAlias($alias)
{
$response = null;
try {
$response = $this->_client->request('/_alias/' . $alias);
} catch (ResponseException $e) {
$transferInfo = $e->getResponse()->getTransferInfo();
// 404 means the index alias doesn't exist which means no indexes have it.
if ($transferInfo['http_code'] === 404) {
return [];
}
// If we don't have a 404 then this is still unexpected so rethrow the exception.
throw $e;
}
$indices = [];
foreach ($response->getData() as $name => $unused) {
$indices[] = new Index($this->_client, $name);
}
return $indices;
}
/** * @group functional */ public function testAliasExists() { $aliasName = 'elastica_test-alias'; $index1 = $this->_createIndex(); $indexName = $index1->getName(); $status = new Status($index1->getClient()); foreach ($status->getIndicesWithAlias($aliasName) as $tmpIndex) { $tmpIndex->removeAlias($aliasName); } $this->assertFalse($status->aliasExists($aliasName)); $index1->addAlias($aliasName); $status->refresh(); $this->assertTrue($status->aliasExists($aliasName)); $indicesWithAlias = $status->getIndicesWithAlias($aliasName); $this->assertEquals(array($indexName), array_map(function ($index) { return $index->getName(); }, $indicesWithAlias)); }