Checks if the given index exists.
public indexExists ( string $name ) : boolean | ||
$name | string | Index name to check |
Результат | boolean | True if index exists |
public function testIndexExists() { $indexName = 'elastica_test'; $aliasName = 'elastica_test-alias'; $client = $this->_getClient(); $index = $client->getIndex($indexName); try { // Make sure index is deleted first $index->delete(); } catch (ResponseException $e) { } $status = new Status($client); $this->assertFalse($status->indexExists($indexName)); $index->create(); $status->refresh(); $this->assertTrue($status->indexExists($indexName)); }
/** * @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)); }