### CI Link

https://gradle-enterprise.elastic.co/s/n6mmfb3uwtq7q

### Repro line

./gradlew ':server:test' --tests "org.elasticsearch.search.internal.ContextIndexSearcherTests.testIntersectScorerAndRoleBits" \   -Dtests.seed=E99DBC08AEFDABC1 \   -Dtests.locale=und \   -Dtests.timezone=America/Santarem \   -Druntime.java=20

### Does it reproduce?

Yes

### Applicable branches

main

### Failure history

_No response_

### Failure excerpt

10:13:31 org.elasticsearch.search.internal.ContextIndexSearcherTests > testIntersectScorerAndRoleBits FAILED
10:13:31     java.lang.AssertionError: The top-reader used to create Weight is not the same as the current reader's top-reader (org.apache.lucene.index.CompositeReaderContext@4afc5040
10:13:31         at __randomizedtesting.SeedInfo.seed([E99DBC08AEFDABC1:41ACDD81C7F3BEAA]:0)
10:13:31         at org.apache.lucene.search.TermQuery$TermWeight.scorer(TermQuery.java:105)
10:13:31         at org.apache.lucene.search.Weight.scorerSupplier(Weight.java:136)
10:13:31         at org.apache.lucene.search.LRUQueryCache$CachingWrapperWeight.scorerSupplier(LRUQueryCache.java:759)
10:13:31         at org.apache.lucene.tests.search.AssertingWeight.scorerSupplier(AssertingWeight.java:80)
10:13:31         at org.apache.lucene.search.ConstantScoreQuery$1.scorerSupplier(ConstantScoreQuery.java:153)
10:13:31         at org.apache.lucene.tests.search.AssertingWeight.scorerSupplier(AssertingWeight.java:80)
10:13:31         at org.apache.lucene.tests.search.AssertingWeight.scorer(AssertingWeight.java:66)
10:13:31         at org.elasticsearch.search.internal.ContextIndexSearcherTests.testIntersectScorerAndRoleBits(ContextIndexSearcherTests.java:157)

server/src/test/java/org/elasticsearch/common/lucene/LuceneTests.java
assertEquals(4, open.maxDoc());
        open.close();
        writer.close();
        SegmentInfos si = Lucene.pruneUnreferencedFiles(segmentCommitInfos.getSegmentsFileName(), dir);
        assertEquals(si.getSegmentsFileName(), segmentCommitInfos.getSegmentsFileName());
        open = DirectoryReader.open(dir);
        assertEquals(3, open.numDocs());
        assertEquals(0, open.numDeletedDocs());
        assertEquals(3, open.maxDoc());
        IndexSearcher s = newSearcher(open);
        assertEquals(s.search(new TermQuery(new Term("id", "1")), 1).totalHits.value, 1);
        assertEquals(s.search(new TermQuery(new Term("id", "2")), 1).totalHits.value, 1);
        assertEquals(s.search(new TermQuery(new Term("id", "3")), 1).totalHits.value, 1);
        assertEquals(s.search(new TermQuery(new Term("id", "4")), 1).totalHits.value, 0);
        for (String file : dir.listAll()) {
            assertFalse("unexpected file: " + file, file.equals("segments_3") || file.startsWith("_2"));
        }
        open.close();
        dir.close();
    }
    public void testFiles() throws IOException {
        MockDirectoryWrapper dir = newMockDirectory();
        IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
        iwc.setMergePolicy(NoMergePolicy.INSTANCE);
        iwc.setMaxBufferedDocs(2);
        iwc.setUseCompoundFile(true);
        IndexWriter writer = new IndexWriter(dir, iwc);
        Document doc = new Document();
        doc.add(new TextField("id", "1", random().nextBoolean() ? Field.Store.YES : Field.Store.NO));
        writer.addDocument(doc);