getIndicesWithAlias() public method

Returns an array with all indices that the given alias name points to.
public getIndicesWithAlias ( string $alias ) : array | Index[]
$alias string Alias name
return array | Index[] List of Elastica\Index
Example #1
0
 /**
  * @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));
 }
Example #2
0
 public function testAliasExists()
 {
     $indexName = 'test';
     $aliasName = 'elastica_test-alias';
     $index1 = $this->_createIndex();
     $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));
 }
Example #3
0
 /**
  * Adds an alias to the current index
  *
  * @param  string $name Alias name
  * @param  bool $replace OPTIONAL If set, an existing alias will be replaced
  * @return \Elastica\Response Response
  * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html
  */
 public function addAlias($name, $replace = false)
 {
     $path = '_aliases';
     $data = array('actions' => array());
     if ($replace) {
         $status = new Status($this->getClient());
         foreach ($status->getIndicesWithAlias($name) as $index) {
             $data['actions'][] = array('remove' => array('index' => $index->getName(), 'alias' => $name));
         }
     }
     $data['actions'][] = array('add' => array('index' => $this->getName(), 'alias' => $name));
     return $this->getClient()->request($path, Request::POST, $data);
 }
 public function validateAlias()
 {
     // @todo utilize the following once Elastica is updated to support passing
     // master_timeout. This is a copy of the Elastica\Index::addAlias() method
     // $this->getIndex()->addAlias( $this->getConnection()->getIndexName( $this->indexBaseName, Connection::TITLE_SUGGEST_TYPE_NAME ), true );
     $index = $this->getIndex();
     $name = $this->getConnection()->getIndexName($this->indexBaseName, Connection::TITLE_SUGGEST_TYPE_NAME);
     $path = '_aliases';
     $data = array('actions' => array());
     $status = new Status($index->getClient());
     foreach ($status->getIndicesWithAlias($name) as $aliased) {
         $data['actions'][] = array('remove' => array('index' => $aliased->getName(), 'alias' => $name));
     }
     $data['actions'][] = array('add' => array('index' => $index->getName(), 'alias' => $name));
     return $index->getClient()->request($path, Request::POST, $data, array('master_timeout' => $this->masterTimeout));
 }