**Build scan:**
https://gradle-enterprise.elastic.co/s/hl6lglm4c2lpi/tests/:server:test/org.elasticsearch.indices.IndicesQueryCacheTests/testStatsOnEviction

**Reproduction line:**
```
./gradlew ':server:test' --tests "org.elasticsearch.indices.IndicesQueryCacheTests.testStatsOnEviction" -Dtests.seed=DF2913E64B9A534B -Dtests.locale=el-CY -Dtests.timezone=Australia/LHI -Druntime.java=19
```

**Applicable branches:**
main

**Reproduces locally?:**
Yes

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.indices.IndicesQueryCacheTests&tests.test=testStatsOnEviction

**Failure excerpt:**
```
java.lang.IllegalArgumentException: Could not extract shard id from ParallelLeafReader(ParallelLeafReader(FilterLeafReader(_0(9.7.0):C1:[diagnostics={os.version=5.4.0-1106-gcp, lucene.version=9.7.0, source=flush, timestamp=1692779641287, java.runtime.version=19.0.2+7-44, java.vendor=Oracle Corporation, os=Linux, os.arch=amd64}]:[attributes={Lucene90StoredFieldsFormat.mode=BEST_SPEED}] :id=ezak3kuhkrvbt5cf9xqakahrk)))

  at __randomizedtesting.SeedInfo.seed([DF2913E64B9A534B:6783AE3FB4A47D8A]:0)
  at org.elasticsearch.common.lucene.ShardCoreKeyMap.doAdd(ShardCoreKeyMap.java:75)
  at org.elasticsearch.common.lucene.ShardCoreKeyMap.add(ShardCoreKeyMap.java:65)
  at org.elasticsearch.indices.IndicesQueryCache$CachingWeightWrapper.count(IndicesQueryCache.java:146)
  at org.apache.lucene.tests.search.AssertingWeight.count(AssertingWeight.java:45)
  at org.apache.lucene.search.TotalHitCountCollector.getLeafCollector(TotalHitCountCollector.java:48)
  at org.apache.lucene.search.FilterCollector.getLeafCollector(FilterCollector.java:38)
  at org.apache.lucene.tests.search.AssertingCollector.getLeafCollector(AssertingCollector.java:52)
  at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:762)
  at org.apache.lucene.tests.search.AssertingIndexSearcher.search(AssertingIndexSearcher.java:78)
  at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:694)
  at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:688)
  at org.apache.lucene.search.IndexSearcher.count(IndexSearcher.java:460)
  at org.elasticsearch.indices.IndicesQueryCacheTests.testStatsOnEviction(IndicesQueryCacheTests.java:316)
  at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
  at java.lang.reflect.Method.invoke(Method.java:578)
  at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1758)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$8.evaluate(RandomizedRunner.java:946)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$9.evaluate(RandomizedRunner.java:982)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$10.evaluate(RandomizedRunner.java:996)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleSetupTeardownChained$1.evaluate(TestRuleSetupTeardownChained.java:48)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at org.apache.lucene.tests.util.TestRuleThreadAndTestName$1.evaluate(TestRuleThreadAndTestName.java:45)
  at org.apache.lucene.tests.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:60)
  at org.apache.lucene.tests.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:44)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:390)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl.forkTimeoutingTask(ThreadLeakControl.java:843)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$3.evaluate(ThreadLeakControl.java:490)
  at com.carrotsearch.randomizedtesting.RandomizedRunner.runSingleTest(RandomizedRunner.java:955)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$5.evaluate(RandomizedRunner.java:840)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$6.evaluate(RandomizedRunner.java:891)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$7.evaluate(RandomizedRunner.java:902)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:38)
  at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
  at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:53)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at org.apache.lucene.tests.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:44)
  at org.apache.lucene.tests.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:60)
  at org.apache.lucene.tests.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:47)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:390)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl.lambda$forkTimeoutingTask$0(ThreadLeakControl.java:850)
  at java.lang.Thread.run(Thread.java:1589)

```
server/src/test/java/org/elasticsearch/indices/IndicesQueryCacheTests.java
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server