### Elasticsearch Version

8.8.2 - 8.9.0

### Installed Plugins

None

### Java Version

_bundled_

### OS Version

ESS

### Problem Description

Note: This is broken in at least both 8.8.2 and 8.9.0. However, I have an instance running with 8.5.x and it does not fail there.

While using a `global` aggregation against a filtered alias that uses a `terms` filter, all search requests fail (see request below with `error_trace` enabled) with a cryptic error:

```http
POST /test-filtered/_search
{
  "aggs": {
    "all_docs": {
      "global": {}
    }
  }
}
```

Response:

```json
{
  "error": {
    "root_cause": [
      {
        "type": "unsupported_operation_exception",
        "reason": "unsupported_operation_exception: Query role:(value) does not implement createWeight"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "test",
        "node": "uLKZu3tzS6aqX6b4FNCZKg",
        "reason": {
          "type": "unsupported_operation_exception",
          "reason": "unsupported_operation_exception: Query role:(value) does not implement createWeight"
        }
      }
    ]
  },
  "status": 500
}
```

### Workaround

You can workaround this by changing the `terms` filter into a `terms_set` filter (with a scripted parameter to return `1` for the required number of matches) _or_ a more verbose, unscripted `bool` / `should` filter without a minimum should match of `1`.

### Steps to Reproduce

```http
DELETE /test

PUT /test
{
  "mappings": {
    "properties": {
      "role": {
        "type": "keyword"
      }
    }
  }
}

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "test",
        "alias": "test-filtered",
        "filter": {
          "terms": {
            "role": [
              "value"
            ]
          }
        }
      }
    }
  ]
}

POST /test-filtered/_search
{
  "aggs": {
    "all_docs": {
      "global": {}
    }
  }
}
```

### Logs (if relevant)

```
{
  "error": {
    "root_cause": [
      {
        "type": "unsupported_operation_exception",
        "reason": "unsupported_operation_exception: Query role:(value) does not implement createWeight",
        "stack_trace": """org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: unsupported_operation_exception: Query role:(value) does not implement createWeight
	at org.apache.lucene.search.Query.createWeight(Query.java:84)
	at org.apache.lucene.search.IndexSearcher.createWeight(IndexSearcher.java:904)
	at org.elasticsearch.search.internal.ContextIndexSearcher.createWeight(ContextIndexSearcher.java:191)
	at org.apache.lucene.search.BooleanWeight.<init>(BooleanWeight.java:59)
	at org.apache.lucene.search.BooleanQuery.createWeight(BooleanQuery.java:245)
	at org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator.<init>(GlobalAggregator.java:34)
	at org.elasticsearch.search.aggregations.bucket.global.GlobalAggregatorFactory.createInternal(GlobalAggregatorFactory.java:52)
	at org.elasticsearch.search.aggregations.AggregatorFactory.create(AggregatorFactory.java:81)
	at org.elasticsearch.search.aggregations.AggregatorFactories.createSubAggregators(AggregatorFactories.java:233)
	at org.elasticsearch.search.aggregations.AggregatorFactories.createTopLevelAggregators(AggregatorFactories.java:243)
	at org.elasticsearch.search.aggregations.AggregationPhase.preProcess(AggregationPhase.java:37)
	at org.elasticsearch.search.query.QueryPhase.executeQuery(QueryPhase.java:146)
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:77)
	at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:470)
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:622)
	at org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:495)
	at org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:50)
	at org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:47)
	at org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:72)
	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:983)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.lang.Thread.run(Thread.java:1623)
"""
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
```
server/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregator.java
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */
package org.elasticsearch.search.aggregations.bucket.global;
import org.apache.lucene.search.BulkScorer;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.Weight;
import org.elasticsearch.search.aggregations.AggregationExecutionContext;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.CardinalityUpperBound;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.LeafBucketCollector;
import org.elasticsearch.search.aggregations.bucket.BucketsAggregator;
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import java.io.IOException;
import java.util.Map;
public class GlobalAggregator extends BucketsAggregator implements SingleBucketAggregator {