Enhancement: document_index reindex --if-needed; simplify Docker startup

Add --if-needed flag to `document_index reindex`: checks _needs_rebuild()
(schema version + language sentinels) and skips if index is up to date.
Safe to run on every upgrade or startup.

Simplify Docker init-search-index script to unconditionally call
`reindex --if-needed` — schema/language change detection is now fully
delegated to Python. Removes the bash index_version and language file
tracking entirely; Tantivy's own sentinels are the source of truth.

Update docs: bare metal upgrade step uses --if-needed; Docker note
updated to describe the new always-runs-but-skips-if-current behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Trenton H
2026-03-30 14:08:49 -07:00
parent ae494d4b6a
commit da3ff7865e
3 changed files with 34 additions and 49 deletions
+12 -14
View File
@@ -180,16 +180,15 @@ following:
This might not actually do anything. Not every new paperless version
comes with new database migrations.
4. Rebuild the search index.
4. Rebuild the search index if needed.
```shell-session
cd src
python3 manage.py document_index reindex
python3 manage.py document_index reindex --if-needed
```
This is required when the search backend has changed (e.g. the upgrade
to Tantivy). It is safe to run on every upgrade — if the index is already
current it completes quickly.
This is a no-op if the index is already up to date, so it is safe to
run on every upgrade.
### Database Upgrades
@@ -480,21 +479,20 @@ task scheduler.
!!! note
**Docker users:** On first startup after upgrading, the container automatically
detects the index format change and runs a full reindex before starting the
webserver. No manual step is required.
**Docker users:** On every startup, the container runs
`document_index reindex --if-needed` automatically. Schema changes, language
changes, and missing indexes are all detected and rebuilt before the webserver
starts. No manual step is required.
**Bare metal users:** After upgrading, run the following command once to rebuild
the search index in the new format:
**Bare metal users:** Run the following command after each upgrade (and after
changing `PAPERLESS_SEARCH_LANGUAGE`). It is a no-op if the index is already
up to date:
```shell-session
cd src
python3 manage.py document_index reindex
python3 manage.py document_index reindex --if-needed
```
Changing `PAPERLESS_SEARCH_LANGUAGE` also requires a manual reindex on bare
metal (Docker handles this automatically).
### Clearing the database read cache
If the database read cache is enabled, **you must run this command** after making any changes to the database outside the application context.