/** * @param string $localSite The wikiId to add/remove from local_sites_with_dupe * @param string $indexName The name of the index to perform updates to * @param aray $otherActions A list of arrays each containing the id within elasticsearch ('id') and the article id within $localSite ('articleId') * @return Status */ public function sendOtherIndexUpdates($localSite, $indexName, array $otherActions) { if (!$this->areIndexesAvailableForWrites(array($indexName), true)) { return Status::newFatal('cirrussearch-indexes-frozen'); } $client = $this->connection->getClient(); $status = Status::newGood(); foreach (array_chunk($otherActions, 30) as $updates) { $bulk = new \Elastica\Bulk($client); $articleIDs = array(); foreach ($updates as $update) { $title = Title::makeTitle($update['ns'], $update['dbKey']); $action = $this->decideRequiredSetAction($title); $this->log->debug("Performing `{$action}` for {$update['dbKey']} in ns {$update['ns']} on {$localSite} against id {$update['id']} in {$indexName}"); $script = new \Elastica\Script('super_detect_noop', array('source' => array('local_sites_with_dupe' => array($action => $localSite)), 'handlers' => array('local_sites_with_dupe' => 'set')), 'native'); $script->setId($update['id']); $script->setParam('_type', 'page'); $script->setParam('_index', $indexName); $bulk->addScript($script, 'update'); $titles[] = $title; } // Execute the bulk update $exception = null; try { $this->start("updating {numBulk} documents in other indexes", array('numBulk' => count($updates))); $bulk->send(); } catch (\Elastica\Exception\Bulk\ResponseException $e) { if (!$this->bulkResponseExceptionIsJustDocumentMissing($e)) { $exception = $e; } } catch (\Elastica\Exception\ExceptionInterface $e) { $exception = $e; } if ($exception === null) { $this->success(); } else { $this->failure($e); $this->failedLog->warning("OtherIndex update for articles: " . implode(',', $titles), array('exception' => $e)); $status->error('cirrussearch-failed-update-otherindex'); } } return $status; }
/** * @param \Elastica\Document[] $documents * @param string|null $shardTimeout Timeout in Elasticsearch time format (1m, 15s, ...) */ protected function sendDocuments(array $documents, $shardTimeout = null) { if (count($documents) === 0) { return; } try { // addDocuments (notice plural) is the bulk api $bulk = new \Elastica\Bulk(Connection::getSingleton()->getClient2()); if ($shardTimeout !== null) { $bulk->setShardTimeout($shardTimeout); } $index = Connection::getFlowIndex(wfWikiId()); $type = $index->getType($this->getTypeName()); $bulk->setType($type); $bulk->addDocuments($documents); $bulk->send(); } catch (\Exception $e) { $documentIds = array_map(function ($doc) { return $doc->getId(); }, $documents); wfWarn(__METHOD__ . ': Failed updating documents (' . implode(',', $documentIds) . '): ' . $e->getMessage()); } }