### Elasticsearch Version

8.9.0-SNAPSHOT built from b5af53d

### Java Version

_bundled_

### OS Version

cloud container

### Problem Description

When an index template is considered to be the highest priority template for an existing data stream it can't be delete, even if a matching index template with a lower priority exists. That means it's not possible to revert a data stream to a lower-priority template without applying a work-around. But as long as there is a matching index template to fall back to, this should be allowed. This is a common sequence of steps when installing and later uninstalling an integration package.

### Steps to Reproduce

Create a logs data stream based on the built-in `logs` index template by indexing a document:

```
POST logs-felixstuermer.test-default/_doc
{
  "@timestamp": "2023-05-05T12:00:00"
}
```

Observe that the data stream considers the default template as its matching template:

```
GET _data_stream/logs-felixstuermer.test-default
```

```json
{
  "data_streams": [
    {
      "name": "logs-felixstuermer.test-default",
      "timestamp_field": {
        "name": "@timestamp"
      },
      "indices": [
        {
          "index_name": ".ds-logs-felixstuermer.test-default-2023.05.11-000001",
          "index_uuid": "moqOcaWvSzG6tMBhCpitjg"
        }
      ],
      "generation": 1,
      "_meta": {
        "description": "default logs template installed by x-pack",
        "managed": true
      },
      "status": "GREEN",
      "template": "logs", // <--
      "ilm_policy": "logs",
      "hidden": false,
      "system": false,
      "allow_custom_routing": false,
      "replicated": false
    }
  ]
}
```

Create a higher-priority index template:

```
PUT _index_template/logs-felixstuermer.test-0
{
  "index_patterns": ["logs-felixstuermer.test-default"],
  "data_stream": { },
  "composed_of": [],
  "priority": 500
}
```

Observe that the data stream now considers the new template as its matching template, even if no rollover has happened:

```
GET _data_stream/logs-felixstuermer.test-default
```

```json
{
  "data_streams": [
    {
      "name": "logs-felixstuermer.test-default",
      "timestamp_field": {
        "name": "@timestamp"
      },
      "indices": [
        {
          "index_name": ".ds-logs-felixstuermer.test-default-2023.05.11-000001",
          "index_uuid": "moqOcaWvSzG6tMBhCpitjg"
        }
      ],
      "generation": 1,
      "_meta": {
        "managed": true,
        "description": "default logs template installed by x-pack"
      },
      "status": "GREEN",
      "template": "logs-felixstuermer.test-0", // <--
      "hidden": false,
      "system": false,
      "allow_custom_routing": false,
      "replicated": false
    }
  ]
}
```

Try to delete the high-priority index template and observe that this fails:

```
DELETE _index_template/logs-felixstuermer.test-0
```

```json
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "unable to remove composable templates [logs-felixstuermer.test-0] as they are in use by a data streams [logs-felixstuermer.test-default]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "unable to remove composable templates [logs-felixstuermer.test-0] as they are in use by a data streams [logs-felixstuermer.test-default]"
  },
  "status": 400
}
```
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java
} catch (IllegalArgumentException iae) {
                validationErrors.add(iae.getMessage());
                for (Throwable t : iae.getSuppressed()) {
                    validationErrors.add(t.getMessage());
                }
            }
            List<String> indexSettingsValidation = metadataCreateIndexService.getIndexSettingsValidationErrors(settings, true);
            validationErrors.addAll(indexSettingsValidation);
        }
        if (indexPatterns.stream().anyMatch(Regex::isMatchAllPattern)) {
            if (settings != null && IndexMetadata.INDEX_HIDDEN_SETTING.exists(settings)) {
                validationErrors.add("global templates may not specify the setting " + IndexMetadata.INDEX_HIDDEN_SETTING.getKey());
            }
        }
        if (validationErrors.size() > 0) {
            ValidationException validationException = new ValidationException();
            validationException.addValidationErrors(validationErrors);
            throw new InvalidIndexTemplateException(name, validationException.getMessage());
        }
        for (Alias alias : aliases) {
            
            AliasValidator.validateAliasStandalone(alias);
            if (indexPatterns.contains(alias.name())) {
                throw new IllegalArgumentException(
                    "alias [" + alias.name() + "] cannot be the same as any pattern in [" + String.join(", ", indexPatterns) + "]"
                );
            }
        }
    }
    public static class PutRequest {