This exception was observed in a Cloud cluster:

```
Failed to execute phase [query], all shards failed; shardFailures {[A6izEymCQDqJ1Ejc2tj1Nw][so][0]: org.elasticsearch.transport.RemoteTransportException: [es-es-search-6fb557dcd5-t2gl4][10.2.145.120:9300][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.search.query.QueryPhaseExecutionException: Query Failed [Failed to execute main query]
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhase.addCollectorsAndSearch(QueryPhase.java:229)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhase.executeQuery(QueryPhase.java:135)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:63)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:518)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:671)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:543)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:51)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:48)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:73)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
	at org.elasticsearch.server@8.12.0/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.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
	at java.base/java.util.Objects.checkIndex(Objects.java:385)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at java.base/java.util.Collections$UnmodifiableList.get(Collections.java:1501)
	at org.elasticsearch.ml@8.12.0/org.elasticsearch.xpack.ml.aggs.frequentitemsets.mr.ItemSetMapReduceAggregator.getLeafReaderForOrdinals(ItemSetMapReduceAggregator.java:225)
	at org.elasticsearch.ml@8.12.0/org.elasticsearch.xpack.ml.aggs.frequentitemsets.mr.ItemSetMapReduceAggregator.<init>(ItemSetMapReduceAggregator.java:79)
	at org.elasticsearch.ml@8.12.0/org.elasticsearch.xpack.ml.aggs.frequentitemsets.FrequentItemSetsAggregatorFactory$1.<init>(FrequentItemSetsAggregatorFactory.java:143)
	at org.elasticsearch.ml@8.12.0/org.elasticsearch.xpack.ml.aggs.frequentitemsets.FrequentItemSetsAggregatorFactory.createInternal(FrequentItemSetsAggregatorFactory.java:129)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorFactory.create(AggregatorFactory.java:80)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorFactories.createSubAggregators(AggregatorFactories.java:233)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorFactories.createTopLevelAggregators(AggregatorFactories.java:243)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregationPhase.newAggregatorCollector(AggregationPhase.java:51)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregationPhase.lambda$preProcess$1(AggregationPhase.java:37)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorCollectorManager.newCollector(AggregatorCollectorManager.java:39)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorCollectorManager.newCollector(AggregatorCollectorManager.java:21)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhaseCollectorManager.newCollector(QueryPhaseCollectorManager.java:139)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:311)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhase.addCollectorsAndSearch(QueryPhase.java:205)
	... 15 more
}
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:709)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:401)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:741)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.search.AbstractSearchAsyncAction.onShardFailure(AbstractSearchAsyncAction.java:494)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:332)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:54)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:553)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.transport.TransportService$UnregisterChildTransportResponseHandler.handleException(TransportService.java:1703)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1420)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1556)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1531)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:51)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.support.ChannelActionListener.onFailure(ChannelActionListener.java:37)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable.onFailure(ActionRunnable.java:124)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
	at org.elasticsearch.server@8.12.0/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: org.elasticsearch.ElasticsearchException$1: Index 0 out of bounds for length 0
	at org.elasticsearch.server@8.12.0/org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:672)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:399)
	... 22 more
Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
	at java.base/java.util.Objects.checkIndex(Objects.java:385)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at java.base/java.util.Collections$UnmodifiableList.get(Collections.java:1501)
	at org.elasticsearch.ml@8.12.0/org.elasticsearch.xpack.ml.aggs.frequentitemsets.mr.ItemSetMapReduceAggregator.getLeafReaderForOrdinals(ItemSetMapReduceAggregator.java:225)
	at org.elasticsearch.ml@8.12.0/org.elasticsearch.xpack.ml.aggs.frequentitemsets.mr.ItemSetMapReduceAggregator.<init>(ItemSetMapReduceAggregator.java:79)
	at org.elasticsearch.ml@8.12.0/org.elasticsearch.xpack.ml.aggs.frequentitemsets.FrequentItemSetsAggregatorFactory$1.<init>(FrequentItemSetsAggregatorFactory.java:143)
	at org.elasticsearch.ml@8.12.0/org.elasticsearch.xpack.ml.aggs.frequentitemsets.FrequentItemSetsAggregatorFactory.createInternal(FrequentItemSetsAggregatorFactory.java:129)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorFactory.create(AggregatorFactory.java:80)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorFactories.createSubAggregators(AggregatorFactories.java:233)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorFactories.createTopLevelAggregators(AggregatorFactories.java:243)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregationPhase.newAggregatorCollector(AggregationPhase.java:51)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregationPhase.lambda$preProcess$1(AggregationPhase.java:37)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorCollectorManager.newCollector(AggregatorCollectorManager.java:39)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.aggregations.AggregatorCollectorManager.newCollector(AggregatorCollectorManager.java:21)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhaseCollectorManager.newCollector(QueryPhaseCollectorManager.java:139)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:311)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhase.addCollectorsAndSearch(QueryPhase.java:205)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhase.executeQuery(QueryPhase.java:135)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:63)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:518)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:671)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:543)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:51)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:48)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:73)
	at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	... 6 more
```

The suspicion is that there is no data and the aggregation is assuming that there is at least 1 segment.
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceAggregator.java
protected void doClose() {
        
        if (breakerService != null) {
            breakerService.disconnect();
        }
        Releasables.close(mapReduceContextByBucketOrdinal);
    }
    private MapContext getMapReduceContext(long bucketOrd) {
        @SuppressWarnings("unchecked")
        MapContext context = (MapContext) mapReduceContextByBucketOrdinal.get(bucketOrd);
        if (context == null) {
            context = mapReducer.mapInit(bigArraysForMapReduce);
            mapReduceContextByBucketOrdinal.put(bucketOrd, context);
        }
        return context;
    }
    private InternalAggregation buildAggregation(long owningBucketOrdinal) throws IOException {
        @SuppressWarnings("unchecked")
        MapFinalContext context = (MapFinalContext) mapReduceContextByBucketOrdinal.get(owningBucketOrdinal);
        if (context == null) {
            return buildEmptyAggregation();
        }
        return new InternalItemSetMapReduceAggregation<>(name, metadata(), mapReducer, context, null, fields, profiling);
    }
    private static LeafReaderContext getLeafReaderForOrdinals(AggregationContext context) {
        IndexReader reader = context.searcher().getIndexReader();
        return reader.leaves().get(0);
    }
}