Esempio n. 1
0
 public function testAliasExists()
 {
     $indexName = 'test';
     $aliasName = 'elastica_test-alias';
     $index1 = $this->_createIndex();
     $status = new Elastica_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));
 }
Esempio n. 2
0
	public function testCreateArray() {
		$client = new Elastica_Client();
		$indexName = 'test';
		$aliasName = 'test-aliase';

		//Testing recreate (backward compatibility)
		$index = $client->getIndex($indexName);
		$index->create(array(), true);
		$status = new Elastica_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 Elastica_Status($client);
		$this->assertTrue($status->indexExists($indexName));

		//Testing invalid options
		try {
			$opts = array('recreate' => true, 'routing' => 'r1,r2', 'testing_invalid_option' => true);
			$index->create(array(), $opts);
			$status = new Elastica_Status($client);
			$this->assertTrue($status->indexExists($indexName));
			$this->fail('Should throw Elastica_Exception_Invalid');
		} catch (Exception $ex) {
			$this->assertTrue($ex instanceof Elastica_Exception_Invalid);
		}
	}
Esempio n. 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';
     if ($replace) {
         $status = new Elastica_Status($this->getClient());
         foreach ($status->getIndicesWithAlias($name) as $index) {
             $index->removeAlias($name);
         }
     }
     $data = array('actions' => array(array('add' => array('index' => $this->getName(), 'alias' => $name))));
     return $this->getClient()->request($path, Elastica_Request::POST, $data);
 }
Esempio n. 4
0
 public function testReplaceAlias()
 {
     $indexName1 = 'test1';
     $indexName2 = 'test2';
     $aliasName = 'test-alias';
     $client = new Elastica_Client();
     $index1 = $client->getIndex($indexName1);
     $index2 = $client->getIndex($indexName2);
     $index1->create(array(), true);
     $index1->addAlias($aliasName);
     $index2->create(array(), true);
     $status = new Elastica_Status($client);
     $this->assertTrue($status->indexExists($indexName1));
     $this->assertTrue($status->indexExists($indexName2));
     $this->assertTrue($status->aliasExists($aliasName));
     $this->assertTrue($index1->getStatus()->hasAlias($aliasName));
     $this->assertFalse($index2->getStatus()->hasAlias($aliasName));
     $index2->addAlias($aliasName, true);
     $this->assertFalse($index1->getStatus()->hasAlias($aliasName));
     $this->assertTrue($index2->getStatus()->hasAlias($aliasName));
 }