### Elasticsearch Version

v8.10+

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

any

### Problem Description

When running a kql query that searches over nested docs, universal highlighter gave a weird error:

```
Caused by: java.lang.IllegalArgumentException: Reader FilterLeafReader(FilterLeafReader(FilterLeafReader(FieldUsageTrackingLeafReader(reader=FilterLeafReader(_1vv(9.7.0):c1303:[diagnostics={java.vendor=Oracle Corporation, os.arch=amd64, os.version=5.10.176+, lucene.version=9.7.0, source=flush, timestamp=1698736883411, java.runtime.version=21+35-2513, os=Linux}]:[attributes={Lucene90StoredFieldsFormat.mode=BEST_SPEED}] :id=5w3udydef33hjzq9jddg14koi))))) does not support caching
```

### Steps to Reproduce

This seems to be caused when we attempt to read from some query cache when utilizing the filter reader provided by the `weight_matches_mode` option in the highlighter. 

That reader is specifically constructed like this:

```
    LeafReader leafReader =
        new FilterLeafReader(_leafReader) {
          @Override
          public Terms terms(String field) throws IOException {
            if (components.getFieldMatcher().test(field)) {
              return super.terms(components.getField());
            } else {
              return super.terms(field);
            }
          }

          //  So many subclasses do this!
          // these ought to be a default or added via some intermediary like
          // "FilterTransientLeafReader" (exception on close).
          @Override
          public CacheHelper getCoreCacheHelper() {
            return null;
          }

          @Override
          public CacheHelper getReaderCacheHelper() {
            return null;
          }
        };
```

### Logs (if relevant)

```
        "reason": "Reader FilterLeafReader(FilterLeafReader(FilterLeafReader(FieldUsageTrackingLeafReader(reader=FilterLeafReader(_1vv(9.7.0):c1303:[diagnostics={java.vendor=Oracle Corporation, os.arch=amd64, os.version=5.10.176+, lucene.version=9.7.0, source=flush, timestamp=1698736883411, java.runtime.version=21+35-2513, os=Linux}]:[attributes={Lucene90StoredFieldsFormat.mode=BEST_SPEED}] :id=5w3udydef33hjzq9jddg14koi))))) does not support caching",
        "stack_trace": """org.elasticsearch.ElasticsearchException$1: Reader FilterLeafReader(FilterLeafReader(FilterLeafReader(FieldUsageTrackingLeafReader(reader=FilterLeafReader(_1vv(9.7.0):c1303:[diagnostics={java.vendor=Oracle Corporation, os.arch=amd64, os.version=5.10.176+, lucene.version=9.7.0, source=flush, timestamp=1698736883411, java.runtime.version=21+35-2513, os=Linux}]:[attributes={Lucene90StoredFieldsFormat.mode=BEST_SPEED}] :id=5w3udydef33hjzq9jddg14koi))))) does not support caching
	at org.elasticsearch.server@8.10.4/org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:667)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.search.SearchPhaseExecutionException.guessRootCauses(SearchPhaseExecutionException.java:150)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:649)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.ElasticsearchException.generateFailureXContent(ElasticsearchException.java:595)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.rest.RestResponse.build(RestResponse.java:176)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.rest.RestResponse.<init>(RestResponse.java:124)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.rest.RestResponse.<init>(RestResponse.java:103)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.rest.action.RestActionListener.onFailure(RestActionListener.java:55)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.rest.action.RestCancellableNodeClient$1.onFailure(RestCancellableNodeClient.java:96)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.client.internal.node.NodeClient$SafelyWrappedActionListener.onFailure(NodeClient.java:171)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.tasks.TaskManager$1.onFailure(TaskManager.java:217)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.support.ContextPreservingActionListener.onFailure(ContextPreservingActionListener.java:39)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations$RunAfterActionListener.onFailure(ActionListenerImplementations.java:269)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.search.AbstractSearchAsyncAction.raisePhaseFailure(AbstractSearchAsyncAction.java:752)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:729)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:419)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:761)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:513)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:350)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:54)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:630)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.transport.TransportService$UnregisterChildTransportResponseHandler.handleException(TransportService.java:1707)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1424)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1560)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1535)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:51)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.support.ChannelActionListener.onFailure(ChannelActionListener.java:37)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionRunnable.onFailure(ActionRunnable.java:124)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.IllegalArgumentException: Reader FilterLeafReader(FilterLeafReader(FilterLeafReader(FieldUsageTrackingLeafReader(reader=FilterLeafReader(_1vv(9.7.0):c1303:[diagnostics={java.vendor=Oracle Corporation, os.arch=amd64, os.version=5.10.176+, lucene.version=9.7.0, source=flush, timestamp=1698736883411, java.runtime.version=21+35-2513, os=Linux}]:[attributes={Lucene90StoredFieldsFormat.mode=BEST_SPEED}] :id=5w3udydef33hjzq9jddg14koi))))) does not support caching
	at org.elasticsearch.server@8.10.4/org.elasticsearch.index.cache.bitset.BitsetFilterCache.getAndLoadIfNotPresent(BitsetFilterCache.java:144)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.index.cache.bitset.BitsetFilterCache$QueryWrapperBitSetProducer.getBitSet(BitsetFilterCache.java:224)
	at org.apache.lucene.join@9.7.0/org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinWeight.scorerSupplier(ToParentBlockJoinQuery.java:150)
	at org.apache.lucene.join@9.7.0/org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinWeight.scorer(ToParentBlockJoinQuery.java:132)
	at org.apache.lucene.join@9.7.0/org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinWeight.matches(ToParentBlockJoinQuery.java:184)
	at org.apache.lucene.core@9.7.0/org.apache.lucene.search.BooleanWeight.matches(BooleanWeight.java:134)
	at org.apache.lucene.core@9.7.0/org.apache.lucene.search.BooleanWeight.matches(BooleanWeight.java:134)
	at org.apache.lucene.core@9.7.0/org.apache.lucene.search.BooleanWeight.matches(BooleanWeight.java:134)
	at org.apache.lucene.core@9.7.0/org.apache.lucene.search.BooleanWeight.matches(BooleanWeight.java:134)
	at org.apache.lucene.highlighter@9.7.0/org.apache.lucene.search.uhighlight.FieldOffsetStrategy.createOffsetsEnumsWeightMatcher(FieldOffsetStrategy.java:147)
	at org.apache.lucene.highlighter@9.7.0/org.apache.lucene.search.uhighlight.FieldOffsetStrategy.createOffsetsEnumFromReader(FieldOffsetStrategy.java:74)
	at org.apache.lucene.highlighter@9.7.0/org.apache.lucene.search.uhighlight.MemoryIndexOffsetStrategy.getOffsetsEnum(MemoryIndexOffsetStrategy.java:119)
	at org.apache.lucene.highlighter@9.7.0/org.apache.lucene.search.uhighlight.FieldHighlighter.highlightFieldForDoc(FieldHighlighter.java:80)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.lucene.search.uhighlight.CustomFieldHighlighter.highlightFieldForDoc(CustomFieldHighlighter.java:63)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.lucene.search.uhighlight.CustomUnifiedHighlighter.highlightField(CustomUnifiedHighlighter.java:147)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.fetch.subphase.highlight.DefaultHighlighter.highlight(DefaultHighlighter.java:81)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.fetch.subphase.highlight.HighlightPhase$1.process(HighlightPhase.java:69)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:158)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:70)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:164)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:77)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:708)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:679)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:541)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:51)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:48)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:73)
	at org.elasticsearch.server@8.10.4/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
```
server/src/main/java/org/elasticsearch/lucene/search/uhighlight/CustomUnifiedHighlighter.java
hasUnknownLeaf[0] = true;
                }
                super.consumeTerms(query, terms);
            }
            @Override
            public void consumeTermsMatching(Query leafQuery, String field, Supplier<ByteRunAutomaton> automaton) {
                if (leafQuery instanceof AbstractScriptFieldQuery) {
                    /**
                     * Queries on runtime fields don't support the matches API.
                     * TODO: We should add the support for keyword runtime fields.
                     */
                    hasUnknownLeaf[0] = true;
                }
                super.consumeTermsMatching(query, field, automaton);
            }
            @Override
            public QueryVisitor getSubVisitor(BooleanClause.Occur occur, Query parent) {
                /**
                 * Nested queries don't support the matches API.
                 */
                if (parent instanceof ESToParentBlockJoinQuery) {
                    hasUnknownLeaf[0] = true;
                }
                return super.getSubVisitor(occur, parent);
            }
        });
        return hasUnknownLeaf[0];
    }
}