### CI Link

https://gradle-enterprise.elastic.co/s/pwrwtjb2rq6p6/tests/:server:internalClusterTest/org.elasticsearch.search.aggregations.metrics.MedianAbsoluteDeviationIT/testAsSubAggregation?expanded-stacktrace=WyIwIl0&top-execution=1

### Repro line

./gradlew ':server:internalClusterTest' --tests "org.elasticsearch.search.aggregations.metrics.MedianAbsoluteDeviationIT.testAsSubAggregation" -Dtests.seed=949133CBE00FFB18 -Dtests.locale=uk -Dtests.timezone=Asia/Jakarta -Druntime.java=20

### Does it reproduce?

Yes

### Applicable branches

main

### Failure history

https://gradle-enterprise.elastic.co/scans/tests?search.startTimeMax=1689086155974&search.startTimeMin=1688418000000&search.timeZoneId=Europe/Bucharest&tests.container=org.elasticsearch.search.aggregations.metrics.MedianAbsoluteDeviationIT&tests.test=testAsSubAggregation

### Failure excerpt

Only failed once in the past 7 days.
```
java.lang.AssertionError: |  
  | Expected: within <10.0> percent of <273574.0> |  
  | but: was <229045.6480914681>
```

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationIT.java
.toArray();
        final Range range = response.getAggregations().get("range");
        assertThat(range, notNullValue());
        List<? extends Range.Bucket> buckets = range.getBuckets();
        assertThat(buckets, notNullValue());
        assertThat(buckets, hasSize(2));
        final Range.Bucket lowerBucket = buckets.get(0);
        assertThat(lowerBucket, notNullValue());
        final MedianAbsoluteDeviation lowerBucketMAD = lowerBucket.getAggregations().get("mad");
        assertThat(lowerBucketMAD, notNullValue());
        assertThat(lowerBucketMAD.getMedianAbsoluteDeviation(), closeToRelative(calculateMAD(lowerBucketSample)));
        final Range.Bucket upperBucket = buckets.get(1);
        assertThat(upperBucket, notNullValue());
        final MedianAbsoluteDeviation upperBucketMAD = upperBucket.getAggregations().get("mad");
        assertThat(upperBucketMAD, notNullValue());
        assertThat(upperBucketMAD.getMedianAbsoluteDeviation(), closeToRelative(calculateMAD(upperBucketSample)));
    }
    @Override
    public void testOrderByEmptyAggregation() throws Exception {
        final int numberOfBuckets = 10;
        final SearchResponse response = client().prepareSearch("idx")
            .setQuery(matchAllQuery())
            .addAggregation(
                terms("terms").field("value")
                    .size(numberOfBuckets)
                    .order(BucketOrder.compound(BucketOrder.aggregation("filter>mad", true)))
                    .subAggregation(
                        filter("filter", termQuery("value", MAX_SAMPLE_VALUE + 1)).subAggregation(randomBuilder().field("value"))
                    )
            )