### Elasticsearch Version

8.3.0

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

All

### Problem Description

In `rest-api-spec/test/analytics/nested_top_metrics_sort.yml` there are the following two tests:

* `terms order by top metrics size greater than 1 rewrite_to_filter_by_filter false`
* `terms order by top metrics size greater than 1 rewrite_to_filter_by_filter true`

Both tests execute the same query. The only difference is in the setting of `rewrite_to_filter_by_filter`, in one case it is `true` in the other it is `false`. The setting determines if the query is rewritten using the so called "filter by filter" optimisation. Query rewriting is an implementation detail and we should make sure the response provided to the client is the same no matter the value of the setting.

Here one query fails with an exception while the other not. We need to make sure the result is the same. We either fail both or we return the same aggregation result.

NOTE: right now the test is not failing because they are written in such a way to highlight the difference. After fixing the issue we expect to have the same result.

### Steps to Reproduce

Just execute the YAML tests.

### Logs (if relevant)

_No response_
x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorTests.java
assertThat(bucket2.getKey(), equalTo(2.0));
        InternalTopMetrics top2 = bucket2.getAggregations().get("test");
        assertThat(top2.getSortOrder(), equalTo(SortOrder.ASC));
        assertThat(top2.getTopMetrics(), equalTo(singletonList(top(4.0, 9.0))));
    }
    public void testTonsOfBucketsTriggersBreaker() throws IOException {
        
        CircuitBreakerService breaker = mock(CircuitBreakerService.class);
        ByteSizeValue max = new ByteSizeValue(20, ByteSizeUnit.KB);
        when(breaker.getBreaker(CircuitBreaker.REQUEST)).thenReturn(new MockBigArrays.LimitedBreaker(CircuitBreaker.REQUEST, max));
        
        try (Directory directory = newDirectory()) {
            try (RandomIndexWriter writer = new RandomIndexWriter(random(), directory)) {
                writer.addDocument(Arrays.asList(doubleField("s", 1.0), doubleField("m", 2.0)));
            }
            try (IndexReader indexReader = DirectoryReader.open(directory)) {
                IndexSearcher indexSearcher = newSearcher(indexReader, false, false);
                TopMetricsAggregationBuilder builder = simpleBuilder(new FieldSortBuilder("s").order(SortOrder.ASC));
                AggregationContext context = createAggregationContext(
                    indexSearcher,
                    createIndexSettings(),
                    new MatchAllDocsQuery(),
                    breaker,
                    builder.bytesToPreallocate(),
                    MultiBucketConsumerService.DEFAULT_MAX_BUCKETS,
                    false,
                    doubleFields()
                );
                Aggregator aggregator = builder.build(context, null).create(null, CardinalityUpperBound.ONE);
                aggregator.preCollection();