{"record":{"id":"1ce3eb0a0773ec09","repo":"phacility/phabricator","slug":"writes-to-search-services-failed-while-reindexing","errorCode":null,"errorMessage":"Writes to search services failed while reindexing document \"%s\".","messagePattern":"Writes to search services failed while reindexing document \"(.+?)\"\\.","errorType":"exception","errorClass":"PhutilAggregateException","httpStatus":null,"severity":"error","filePath":"src/infrastructure/cluster/search/PhabricatorSearchService.php","lineNumber":234,"sourceCode":"  public static function reindexAbstractDocument(\n    PhabricatorSearchAbstractDocument $document) {\n\n    $exceptions = array();\n    foreach (self::getAllServices() as $service) {\n      if (!$service->isWritable()) {\n        continue;\n      }\n\n      $engine = $service->getEngine();\n      try {\n        $engine->reindexAbstractDocument($document);\n      } catch (Exception $ex) {\n        $exceptions[] = $ex;\n      }\n    }\n\n    if ($exceptions) {\n      throw new PhutilAggregateException(\n        pht(\n          'Writes to search services failed while reindexing document \"%s\".',\n          $document->getPHID()),\n        $exceptions);\n    }\n  }\n\n  /**\n   * Execute a full-text query and return a list of PHIDs of matching objects.\n   * @return string[]\n   * @throws PhutilAggregateException\n   */\n  public static function executeSearch(PhabricatorSavedQuery $query) {\n    $result_set = self::newResultSet($query);\n    return $result_set->getPHIDs();\n  }\n\n  public static function newResultSet(PhabricatorSavedQuery $query) {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/cluster/search/PhabricatorSearchService.php#L216-L252","documentation":"PhabricatorSearchService::reindexAbstractDocument() writes the document to every writable search service and collects per-service exceptions instead of dropping them. If any writable engine throws (connection refused, mapping error, version mismatch, timeout), all failures are wrapped in a PhutilAggregateException carrying the document PHID, so callers can detect that the index is missing this document.","triggerScenarios":"Running `bin/search index` or saving/creating objects while a writable backend fails: Elasticsearch node down, index mapping changed after a version bump, wrong `version`/`protocol`/`path` in `cluster.search`, or network timeouts. Each failing writable service contributes its exception to the aggregate.","commonSituations":"Reindexing after upgrading the search backend (mapping incompatibilities); network partition between app hosts and the search cluster; credentials or index permissions changed mid-reindex.","solutions":["Catch PhutilAggregateException and iterate `$ex->getExceptions()` to see which backend failed and why (connection vs mapping vs version).","Restore the failing backend, then re-run the reindex — indexing is idempotent and will fill the gap.","If mappings changed, recreate the index and reindex from scratch rather than patching documents.","Temporarily mark failing hosts non-writable via their `roles` map so writes stop routing to a dead backend while you repair it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  PhabricatorSearchService::reindexAbstractDocument($document);\n} catch (PhutilAggregateException $ex) {\n  foreach ($ex->getExceptions() as $cause) {\n    phlog('search reindex failure: '.$cause->getMessage());\n  }\n  // indexing is idempotent: queue the PHID for a later retry pass\n  // rather than failing the whole job\n}","preventionTips":["Treat reindex failures as retryable background work (queue the PHID), not fatal errors in the request path.","Keep `bin/search index` in periodic scheduled runs so gaps from transient outages self-heal.","Mark known-dead hosts non-writable via roles instead of letting every write attempt fail and aggregate."],"tags":["php","phabricator","search","reindex","elasticsearch","cluster"],"backgroundTag":"search-index-write-failed","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}