**Build scan:**
https://gradle-enterprise.elastic.co/s/xl4uqehihgkxs/tests/:x-pack:plugin:rollup:test/org.elasticsearch.xpack.rollup.v2.RollupActionSingleNodeTests/testRollupDatastream

**Reproduction line:**
`./gradlew ':x-pack:plugin:rollup:test' --tests "org.elasticsearch.xpack.rollup.v2.RollupActionSingleNodeTests.testRollupDatastream" -Dtests.seed=4E779F8B2A344C56 -Dtests.locale=sl -Dtests.timezone=NST -Druntime.java=18`

**Applicable branches:**
main

**Reproduces locally?:**
No

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.xpack.rollup.v2.RollupActionSingleNodeTests&tests.test=testRollupDatastream

**Failure excerpt:**
```
org.elasticsearch.action.search.SearchPhaseExecutionException: 
  at __randomizedtesting.SeedInfo.seed([4E779F8B2A344C56:84AC3906E3AE0A19]:0)
  at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:728)
  at org.elasticsearch.action.search.FetchSearchPhase$1.onFailure(FetchSearchPhase.java:95)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28)
  at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
  at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:769)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  at java.lang.Thread.run(Thread.java:833)

  Caused by: org.elasticsearch.search.aggregations.MultiBucketConsumerService$TooManyBucketsException: Trying to create too many buckets. Must be less than or equal to: [65536] but this number of buckets was exceeded. This limit can be set by changing the [search.max_buckets] cluster level setting.

    at org.elasticsearch.search.aggregations.MultiBucketConsumerService$MultiBucketConsumer.accept(MultiBucketConsumerService.java:115)
    at org.elasticsearch.search.aggregations.AggregationReduceContext$ForFinal.consumeBucketCountAndMaybeBreak(AggregationReduceContext.java:213)
    at org.elasticsearch.search.aggregations.AggregationReduceContext.consumeBucketsAndMaybeBreak(AggregationReduceContext.java:119)
    at org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram.addEmptyBuckets(InternalDateHistogram.java:407)
    at org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram.reduce(InternalDateHistogram.java:476)
    at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:159)
    at org.elasticsearch.search.aggregations.bucket.terms.AbstractInternalTerms.reduceBucket(AbstractInternalTerms.java:109)
    at org.elasticsearch.search.aggregations.DelayedBucket.reduced(DelayedBucket.java:59)
    at org.elasticsearch.search.aggregations.TopBucketBuilder$BufferingTopBucketBuilder.build(TopBucketBuilder.java:180)
    at org.elasticsearch.search.aggregations.bucket.terms.AbstractInternalTerms.reduce(AbstractInternalTerms.java:315)
    at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:159)
    at org.elasticsearch.search.aggregations.InternalAggregations.topLevelReduce(InternalAggregations.java:106)
    at org.elasticsearch.action.search.SearchPhaseController.reduceAggs(SearchPhaseController.java:601)
    at org.elasticsearch.action.search.SearchPhaseController.reducedQueryPhase(SearchPhaseController.java:570)
    at org.elasticsearch.action.search.QueryPhaseResultConsumer.reduce(QueryPhaseResultConsumer.java:130)
    at org.elasticsearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:104)
    at org.elasticsearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:90)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:769)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.lang.Thread.run(Thread.java:833)

```
x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/v2/RollupActionSingleNodeTests.java
protected Collection<Class<? extends Plugin>> getPlugins() {
        return List.of(
            LocalStateCompositeXPackPlugin.class,
            Rollup.class,
            AnalyticsPlugin.class,
            AggregateMetricMapperPlugin.class,
            DataStreamsPlugin.class,
            IndexLifecycle.class
        );
    }
    @Before
    public void setup() {
        sourceIndex = randomAlphaOfLength(14).toLowerCase(Locale.ROOT);
        rollupIndex = "rollup-" + sourceIndex;
        startTime = randomLongBetween(946769284000L, 1607470084000L); 
        docCount = randomIntBetween(10, 9000);
        numOfShards = randomIntBetween(1, 4);
        numOfReplicas = randomIntBetween(0, 3);
        
        dimensionValues = new ArrayList<>(MAX_DIM_VALUES);
        for (int j = 0; j < randomIntBetween(1, MAX_DIM_VALUES); j++) {
            dimensionValues.add(randomAlphaOfLength(6));
        }
        /**
         * NOTE: here we map each numeric label field also as a (counter) metric.
         * This is done for testing purposes. There is no easy way to test
         * that labels are collected using the last value. The idea is to
         * check that the value of the label (last value) matches the value
         * of the corresponding metric which uses a last_value metric type.
         */