Elastica\Type::exists PHP Method

exists() public method

Checks if the given type exists in Index.
public exists ( ) : boolean
return boolean True if type exists
    public function exists()
    {
        $response = $this->getIndex()->request($this->getName(), Request::HEAD);
        $info = $response->getTransferInfo();
        return $info['http_code'] == 200;
    }

Usage Example

 /**
  * 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";
             }
         }
     }
 }
All Usage Examples Of Elastica\Type::exists