Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $indexName = $this->option('index') ?: $this->indexManager->getDefaultIndex();
     $reset = $this->option('reset') ?: false;
     if ($this->indexManager->indicesExist([$indexName])) {
         if ($reset) {
             $this->resetIndex($indexName);
         } else {
             $this->error("Index '{$indexName}' already exists, exiting. Use --reset to force the creation of a new index.");
             return 1;
         }
     }
     $settings = [];
     $shards = $this->option('shards');
     if (!is_null($shards)) {
         $settings['number_of_shards'] = $shards;
     }
     $replicas = $this->option('replicas');
     if (!is_null($replicas)) {
         $settings['number_of_replicas'] = $replicas;
     }
     $this->createIndex($indexName, $settings);
     $this->info("Index '{$indexName}' successfully created.");
 }