Skip to content

SOLR-12239: add RESORTINDEX core-admin action to re-sort an existing index#4644

Open
serhiy-bzhezytskyy wants to merge 1 commit into
apache:mainfrom
serhiy-bzhezytskyy:SOLR-12239-index-sort-existing-collection
Open

SOLR-12239: add RESORTINDEX core-admin action to re-sort an existing index#4644
serhiy-bzhezytskyy wants to merge 1 commit into
apache:mainfrom
serhiy-bzhezytskyy:SOLR-12239-index-sort-existing-collection

Conversation

@serhiy-bzhezytskyy

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-12239

Enabling an index sort on an existing collection currently fails on core reload with IndexWriter's validateIndexSort ("cannot change previous indexSort") — Lucene rejects the transition from unsorted segments to a configured sort, so today you have to delete and reindex from source.

This adds a RESORTINDEX core-admin action that re-sorts the existing index into a target sort order and swaps it in, without reindexing.

Mechanism (LUCENE-9484, shipped in Lucene 9.0): each existing segment reader is wrapped in a SortingCodecReader and merged into a fresh sort-configured IndexWriter via addIndexes(CodecReader...); the result is swapped in with modifyIndexProps (the same path RestoreCore/replication use), then the writer and searcher are reopened. Note addIndexes does not auto-sort unsorted readers (LUCENE-8505 removed that), so the explicit SortingCodecReader wrap is what performs the re-sort.

Details:

  • v1 (action=RESORTINDEX&core=X&sort=...) and v2 (POST /api/cores/X/resort) APIs; v1 delegates to the v2 impl.
  • Target sort is the sort param (usual Solr sort syntax), or falls back to the core's configured SortingMergePolicy sort if omitted.
  • Not supported in SolrCloud mode.
  • Indexes with child/nested documents are rejected (re-sorting would break the parent-child blocks).
  • The re-sort writer mirrors SolrIndexConfig's parent-field handling so it works on child-doc-capable schemas.
  • Failed swap rolls back to the original index (RestoreCore's pattern).
  • Tests: v1 (happy path, unparseable-sort, no-sort-and-none-configured, child-doc rejection), config-sort fallback, and the v2 API directly. Ref-guide + changelog included.

I see this as the migration piece that complements SOLR-13681 / #313 (making the index sort configurable) — resort an existing index, then declare the matching sort in config so new docs stay sorted. Filing as a PoC/for discussion: does this approach fit with how index sorting should evolve? Happy to adjust. I did not want to step on the config work.

…index

Enabling index sorting on a collection created without it currently fails on core
reload with an IndexWriter.validateIndexSort error, forcing a delete + reindex from
source. This adds a RESORTINDEX core-admin action that re-sorts the existing index
into the requested sort order in place, using the LUCENE-9484 mechanism: each segment
reader is wrapped in a SortingCodecReader and merged into a fresh sort-configured
IndexWriter via addIndexes(CodecReader...), and the result is swapped in with
modifyIndexProps (as RestoreCore/replication do), then the writer and searcher are
reopened.

Notes:
- addIndexes does not auto-sort unsorted readers (LUCENE-8505 removed that), so the
  explicit SortingCodecReader wrap is what performs the merge-based re-sort.
- Not supported in SolrCloud mode.
- Indexes containing child/nested documents are rejected (re-sorting would break the
  parent-child blocks), matching UPGRADEINDEX's restriction.
- On a failed swap the original index.properties is restored (RestoreCore's rollback).

The target sort is given by the sort request parameter using the usual Solr sort
syntax; the fields must have docValues.
@github-actions github-actions Bot added documentation Improvements or additions to documentation client:solrj tests cat:api labels Jul 16, 2026
@dsmiley dsmiley requested a review from cpoerschke July 16, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:api client:solrj documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant