public function testIndexExists() { $indexName = 'elastica_test'; $aliasName = 'elastica_test-alias'; $client = new Elastica_Client(); $index = $client->getIndex($indexName); try { // Make sure index is deleted first $index->delete(); } catch (Elastica_Exception_Response $e) { } $status = new Elastica_Status($client); $this->assertFalse($status->indexExists($indexName)); $index->create(); $status->refresh(); $this->assertTrue($status->indexExists($indexName)); }
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); } }
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)); }