> ## Documentation Index
> Fetch the complete documentation index at: https://nikita-shkoda.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Reindexing

> Fastest ways to rebuild with schema changes.

Related: <a href="/projects/search-engine-for-typesense/v29/schema">Schema</a>, <a href="/projects/search-engine-for-typesense/v29/indexer">Indexer</a>, <a href="/projects/search-engine-for-typesense/v29/cli">CLI</a>, <a href="/projects/search-engine-for-typesense/v29/schema-indexer-e2e">Schema + Indexer E2E</a>

Use this page when you need to reindex a collection with schema changes.

<Note>
  Examples assume the <code>SearchEngine::Book</code> model from <a href="/projects/search-engine-for-typesense/v29/guidebook-model-configuration">Model configuration</a>.
</Note>

## Fastest ways to reindex

<Steps>
  <Step title="CLI (safe blue/green)">
    ```bash theme={null}
    rails 'search_engine:schema:apply[books]'
    rails 'search_engine:schema:rollback[books]'
    ```
  </Step>

  <Step title="Ruby (auto fix drift)">
    ```ruby theme={null}
    SearchEngine::Book.index_collection(pre: :index)
    SearchEngine::Bulk.index_collections(:books, :publishers)
    ```
  </Step>
</Steps>

<Warning>
  <code>reindex\_collection!</code> and <code>Bulk.reindex\_all!</code> drop the
  active physical collection. Use only when destructive reindexing is safe.
</Warning>

## Destructive reindex (only if safe)

```ruby theme={null}
SearchEngine::Book.reindex_collection!
SearchEngine::Bulk.reindex_all!
```

## Retention settings

Keep a limited number of old physical collections after swaps:

```ruby theme={null}
class SearchEngine::Book < SearchEngine::Base
  schema_retention keep_last: 2
end
```

## Next steps

* See <a href="/projects/search-engine-for-typesense/v29/schema">Schema</a> for
  diff rules and retention behavior.
* Use <a href="/projects/search-engine-for-typesense/v29/observability">Observability</a>
  to track schema apply and reindex events.
