exists() public method

Checks if the given type exists in Index.
public exists ( ) : boolean
return boolean True if type exists
コード例 #1
0
 /**
  * Create new mappings or update existing mappings
  */
 public function updateMappings()
 {
     /** @var ClassMetadata[] $metadatas */
     $metadatas = $this->sm->getMetadataFactory()->getAllMetadata();
     // Refresh all the mappings
     foreach ($metadatas as $metadata) {
         // if we're in the dev env, set the number of replicas to be 0
         if ($this->env == 'dev' || $this->env == 'test_local') {
             $metadata->numberOfReplicas = 0;
         }
         // create the index if it doesn't exist yet
         $indexName = $metadata->timeSeriesScale ? $metadata->getCurrentTimeSeriesIndex() : $metadata->index;
         /** @var Index $index */
         $index = $this->client->getIndex($indexName);
         if (!$index->exists()) {
             $this->client->createIndex($indexName, $metadata->getSettings());
         }
         // create the type if it doesn't exist yet
         if ($metadata->type) {
             $type = new Type($index, $metadata->type);
             if (!$type->exists()) {
                 $this->client->createType($metadata);
             }
             // update the mapping
             $result = $this->client->updateMapping($metadata);
             if (true !== $result) {
                 echo "Warning: Failed to update mapping for index '{$indexName}', type '{$metadata->type}'. Reason: {$result}\n";
             }
         }
     }
 }
コード例 #2
0
 /**
  * Get the currentType
  *
  * @param      $type
  * @param bool $createNew
  *
  * @return \Elastica\Type
  */
 public function getType($type, $createNew = false)
 {
     $this->_type = $this->_index->getType($type);
     if ($createNew == true && $this->_type->exists() == true) {
         $this->_type->delete();
     }
     return $this->_type;
 }
コード例 #3
0
 /**
  * @param string $typeName
  * @return \Elastica\Type
  * @throws \Exception
  */
 protected function deleteMapping($typeName)
 {
     $type = new Elastica\Type($this->index, $typeName);
     if ($type->exists()) {
         try {
             $type->delete();
         } catch (\Exception $e) {
             throw new \Exception('Could not delete type ' . $type->getName() . '');
         }
     }
     $type = new Elastica\Type($this->index, $typeName);
     return $type;
 }
コード例 #4
0
ファイル: TypeTest.php プロジェクト: bungkoko/Elastica
 /**
  * @group functional
  */
 public function testExists()
 {
     $index = $this->_createIndex();
     $this->assertTrue($index->exists());
     $type = new Type($index, 'user');
     $this->assertFalse($type->exists());
     $type->addDocument(new Document(1, array('name' => 'test name')));
     $index->optimize();
     // sleep a moment to be sure that all nodes in cluster has new type
     sleep(5);
     //Test if type exists
     $this->assertTrue($type->exists());
     $index->delete();
     $this->assertFalse($index->exists());
 }
コード例 #5
0
ファイル: TypeTest.php プロジェクト: tkaven/Elastica
 public function testExists()
 {
     $index = $this->_createIndex();
     $this->assertTrue($index->exists());
     $type = new Type($index, 'user');
     $this->assertFalse($type->exists());
     $type->addDocument(new Document(1, array('name' => 'test name')));
     $index->optimize();
     //Test if type exists
     $this->assertTrue($type->exists());
     $index->delete();
     $this->assertFalse($index->exists());
 }