コード例 #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";
             }
         }
     }
 }