### Description

We have had this longstanding issue that running a top-level `filter` aggregation is often (not always, e.g. not if you need the total hit count too) a performance bug, as Elasticsearch would iterate over docs that match the `query` and would then check each of these docs against the filter of the `filter` aggregation. It's usually a better idea to put the filter directly into the query, where it can be used to drive iteration if appropriate.

We could do this automatically by implementing the `LeafCollector#competitiveIterator` API that was introduced for dynamic pruning, in order to automatically start intersecting the query with the filter of the `filter` aggregator once enough hits have been counted.
server/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterByFilterAggregator.java
private final String name;
        private final List<QueryToFilterAdapter> filters = new ArrayList<>();
        private final boolean keyed;
        private final boolean keyedBucket;
        private final AggregationContext aggCtx;
        private final Aggregator parent;
        private final CardinalityUpperBound cardinality;
        private final Map<String, Object> metadata;
        private final Query rewrittenTopLevelQuery;
        private boolean valid = true;
        public AdapterBuilder(
            String name,
            boolean keyed,
            boolean keyedBucket,
            String otherBucketKey,
            AggregationContext aggCtx,
            Aggregator parent,
            CardinalityUpperBound cardinality,
            Map<String, Object> metadata
        ) throws IOException {
            this.name = name;
            this.keyed = keyed;
            this.keyedBucket = keyedBucket;
            this.aggCtx = aggCtx;
            this.parent = parent;
            this.cardinality = cardinality;
            this.metadata = metadata;
            this.rewrittenTopLevelQuery = aggCtx.searcher().rewrite(aggCtx.query());
            this.valid = parent == null && otherBucketKey == null && aggCtx.isInSortOrderExecutionRequired() == false;
        }