phacility/phabricator · error · Exception

Failed to rebuild search index for any documents.

Error message

Failed to rebuild search index for any documents.

What it means

Thrown by `bin/search index` after iterating all selected documents: not a single document reindexed successfully ($any_success stayed false). Each per-document failure was caught and logged with phlog(), so the real exceptions appear earlier in output. This is an aggregate signal that the search backend is rejecting or failing every write, not a problem with one object.

Source

Thrown at src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php:258

          } else if ($old_versions !== $new_versions) {
            $count_updated++;
          } else {
            $count_skipped++;
          }
        }

        $any_success = true;
      } catch (Exception $ex) {
        phlog($ex);
      }

      $bar->update(1);
    }

    $bar->done();

    if (!$any_success) {
      throw new Exception(
        pht('Failed to rebuild search index for any documents.'));
    }

    if ($track_skips) {
      if ($count_updated) {
        $this->logOkay(
          pht('DONE'),
          pht(
            'Updated search indexes for %s document(s).',
            new PhutilNumber($count_updated)));
      }

      if ($count_skipped) {
        $this->logWarn(
          pht('SKIP'),
          pht(
            'Skipped %s documents(s) which have not updated since they were '.
            'last indexed.',

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Scroll up in the output and read the phlog'd per-document exceptions - they carry the root cause
  2. Run `bin/search status` to confirm every configured host is healthy
  3. Check ES cluster health and disk watermarks: curl http://host:9200/_cluster/health
  4. If indices are stale or mappings are incompatible, reinitialize the index (bin/search init in this workflow family) and then reindex
  5. Smoke-test with one document first: `bin/search index D1`

Example fix

# before: mass reindex with a broken backend
bin/search index --all

# after: verify, smoke-test one document, then bulk
bin/search status
bin/search index D1
bin/search index --all
Defensive patterns

Strategy: try-catch

Validate before calling

// Preflight the backend before any bulk reindex
exec('./bin/search status', $output, $code);
if ($code !== 0) {
  // fix the search service before reindexing
}

Try / catch

try {
  $workflow->execute($args); // reindex selected documents
} catch (Exception $ex) {
  if (strpos($ex->getMessage(), 'Failed to rebuild search index') === 0) {
    // zero documents succeeded: inspect phlog'd per-document exceptions,
    // repair the backend, then retry from the first document
  }
}

Prevention

When it happens

Trigger: `bin/search index --all` (or any selector) when the configured search service is down or misconfigured, the Elasticsearch index/mappings are missing or incompatible (e.g. after an ES upgrade without re-init), writes return 4xx/5xx for every document, or every selected object raises during indexing.

Common situations: Elasticsearch stopped or unreachable; cluster.search misconfigured (see the invalid-JSON error); index deleted or never initialized after switching engines; ES upgraded and mapping types no longer accepted; ES node out of disk (flood-stage blocks writes); running reindex before the search service started.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/3f0a53789e9c9921. Report an issue: GitHub.