Similar to the bug reported in https://github.com/elastic/elasticsearch/issues/100186, it seems that stats over multiple indices where some might be missing the column generate errors:

    FROM logs-* | STATS count=count(*) BY agent.version

Results in:

    ValuesSources are mismatched

This happens in benchmarking tests where very little data is generated. The full benchmarks have all data generated, and the error does not occur, so we presume the issue might be either:

* A mismatch between documents created and index mappings
* Or missing data in indexes that do have this field mapped

The error trace is:

```
java.lang.IllegalStateException: ValuesSources are mismatched
	at org.elasticsearch.compute.operator.OrdinalsGroupingOperator.<init>(OrdinalsGroupingOperator.java:102)
	at org.elasticsearch.compute.operator.OrdinalsGroupingOperator.get(OrdinalsGroupingOperator.java:64)
	at org.elasticsearch.xpack.esql.planner.LocalExecutionPlanner.lambda-zsh(LocalExecutionPlanner.java:646)
	at java.base/java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:197)
	at java.base/java.util.ArrayList.forEachRemaining(ArrayList.java:1625)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at org.elasticsearch.xpack.esql.planner.LocalExecutionPlanner.operators(LocalExecutionPlanner.java:646)
	at org.elasticsearch.xpack.esql.planner.LocalExecutionPlanner.apply(LocalExecutionPlanner.java:730)
	at org.elasticsearch.xpack.esql.planner.LocalExecutionPlanner.createDrivers(LocalExecutionPlanner.java:773)
	at org.elasticsearch.xpack.esql.plugin.ComputeService.runCompute(ComputeService.java:265)
	at org.elasticsearch.xpack.esql.plugin.ComputeService.lambda(ComputeService.java:432)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.action.ActionListener.onResponse(ActionListener.java:177)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.action.ActionListener.completeWith(ActionListener.java:305)
	at org.elasticsearch.xpack.esql.plugin.ComputeService.lambda(ComputeService.java:301)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.index.shard.IndexShard.ensureShardSearchActive(IndexShard.java:3932)
	at org.elasticsearch.xpack.esql.plugin.ComputeService.acquireSearchContexts(ComputeService.java:299)
	at org.elasticsearch.xpack.esql.plugin.ComputeService.messageReceived(ComputeService.java:430)
	at org.elasticsearch.xpack.esql.plugin.ComputeService.messageReceived(ComputeService.java:422)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.transport.TransportService.doRun(TransportService.java:1020)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext.doRun(ThreadContext.java:983)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext.doRun(ThreadContext.java:983)
	at org.elasticsearch.server@8.12.0-SNAPSHOT/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.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1623)
```

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionIT.java
public void testTopNPushedToLuceneOnSortedIndex() {
        var sortOrder = randomFrom("asc", "desc");
        createAndPopulateIndex(
            "sorted_test_index",
            Settings.builder().put("index.sort.field", "time").put("index.sort.order", sortOrder).build()
        );
        int limit = randomIntBetween(1, 5);
        try (EsqlQueryResponse results = run("from sorted_test_index | sort time " + sortOrder + " | limit " + limit + " | keep time")) {
            logger.info(results);
            Assert.assertEquals(1, results.columns().size());
            Assert.assertEquals(limit, getValuesList(results).size());
            
            assertEquals("time", results.columns().get(0).name());
            assertEquals("long", results.columns().get(0).type());
            boolean sortedDesc = "desc".equals(sortOrder);
            var expected = LongStream.range(0, 40)
                .map(i -> epoch + i)
                .boxed()
                .sorted(sortedDesc ? reverseOrder() : naturalOrder())
                .limit(limit)
                .toList();
            var actual = getValuesList(results).stream().map(l -> (Long) l.get(0)).toList();
            assertThat(actual, equalTo(expected));
        }
    }
    /*
     * Create two indices that both have nested documents in them. Create an alias pointing to the two indices.
     * Query an individual index, then query the alias checking that no nested documents are returned.
     */
    public void testReturnNoNestedDocuments() throws IOException, ExecutionException, InterruptedException {