/** * @param array $add * @param array $remove * @return \Status */ protected function updateIndices(array $add, array $remove) { $data = array(); $this->output("alias not already assigned to this index..."); // We'll remove the all alias from the indices that we're about to delete while // we add it to this index. Elastica doesn't support this well so we have to // build the request to Elasticsearch ourselves. foreach ($add as $indexName) { $data['action'][] = array('add' => array('index' => $indexName, 'alias' => $this->aliasName)); } foreach ($remove as $indexName) { $data['action'][] = array('remove' => array('index' => $indexName, 'alias' => $this->aliasName)); } $this->client->request('_aliases', \Elastica\Request::POST, $data); $this->output("corrected\n"); return parent::updateIndices($add, $remove); }
/** * @param array $add * @param array $remove * @return Status */ protected function updateIndices(array $add, array $remove) { if (!$remove) { return $this->updateFreeIndices($add); } if (!$this->reindexAndRemoveOk) { $this->output("cannot correct!\n"); return Status::newFatal(new RawMessage("The alias is held by another index which means it might be actively serving\n" . "queries. You can solve this problem by running this program again with\n" . "--reindexAndRemoveOk. Make sure you understand the consequences of either\n" . "choice.")); } try { $this->output("is taken...\n"); $this->outputIndented("\tReindexing...\n"); call_user_func_array(array($this->reindexer, 'reindex'), $this->reindexParams); if ($this->tooFewReplicas) { $this->reindexer->optimize(); foreach ($this->reindexValidators as $validator) { $status = $validator->validate(); if (!$status->isOK()) { return $status; } } $this->reindexer->waitForShards(); } } catch (\Exception $e) { return Status::newFatal(new RawMessage($e->getMessage())); } // now add alias & remove indices for real $status = Status::newGood(); $status->merge($this->swapAliases($add)); $status->merge(parent::updateIndices(array(), $remove)); return $status; }