コード例 #1
0
ファイル: StatusTest.php プロジェクト: kskod/Elastica
 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));
 }
コード例 #2
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));
 }
コード例 #3
0
ファイル: IndexTest.php プロジェクト: kskod/Elastica
 /**
  * @expectedException \Elastica\Exception\InvalidException
  */
 public function testCreateArray()
 {
     $client = $this->_getClient();
     $indexName = 'test';
     //Testing recreate (backward compatibility)
     $index = $client->getIndex($indexName);
     $index->create(array(), true);
     $status = new Status($client);
     $this->assertTrue($status->indexExists($indexName));
     //Testing create index with array options
     $opts = array('recreate' => true, 'routing' => 'r1,r2');
     $index->create(array(), $opts);
     $status = new Status($client);
     $this->assertTrue($status->indexExists($indexName));
     //Testing invalid options
     $opts = array('recreate' => true, 'routing' => 'r1,r2', 'testing_invalid_option' => true);
     $index->create(array(), $opts);
     $status = new Status($client);
     $this->assertTrue($status->indexExists($indexName));
 }
コード例 #4
0
ファイル: Index.php プロジェクト: javik223/Evron-Magento
 /**
  * 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);
 }
コード例 #5
0
 /**
  * Refresh elastica status
  */
 protected function refreshStatus()
 {
     if ($this->status) {
         $this->status->refresh();
     }
 }
 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));
 }