### Elasticsearch Version

7.x, 8.x

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

Darwin 

### Problem Description

A data stream must have an index template that matches it in order to exist.
When managing index templates we want to make sure we don't leave a
data stream without a [corresponding index template](https://github.com/elastic/elasticsearch/blob/acf9968f9d397d755d5ad9fcf815cca23bbeda61/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java#L918).

The `dataStreamsUsingTemplate` check uses the index pattern of the index 
templates to conclude if a template is used by a data stream, however it should
be enhanced to check the priority too as there can only be only one index template
that matches a data stream and it's the one with the highest priority.

### Steps to Reproduce

Create an ILM policy
```
PUT _ilm/policy/testing_yo
{
  "policy": {
    "phases": {
      "warm": {
	"actions": {
	  "shrink": {
          "number_of_shards": 1
	  }
        }
      }
    } 
  }
}
```

Create an index template with the `data_stream` option:
```
PUT _index_template/logs_data_stream
{
	"index_patterns": [ "logs*", "te*", "bar*" ],
	"data_stream": {},
        "priority": 100,
	"template" : {
	  "settings": {
            "index.number_of_shards": 3,
	    "index.lifecycle.name": "testing"
	  }
	}
}
```

Create the data stream
```
POST logs_test/_doc 
{
  "message": "testing",
  "@timestamp": "1591890611"
}
```

Create a new index template that would match this data stream with a higher priority
```
PUT _index_template/higher_logs_data_stream
{
	"index_patterns": [ "logs*", "te*", "bar*" ],
	"data_stream": {},
        "priority": 500,
	"template" : {
	  "settings": {
            "index.number_of_shards": 3,
	    "index.lifecycle.name": "testing"
	  }
	}
}
```

Attempt to delete the previous, lower priority index template:
```
DELETE _index_template/logs_data_stream
```

### Logs (if relevant)

_No response_
modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamIT.java
assertThat(getIndexResponse.getIndices(), hasItemInArray("logs-barfoo3"));
        DeleteDataStreamAction.Request deleteDSReq = new DeleteDataStreamAction.Request(new String[] { "*" });
        client().execute(DeleteDataStreamAction.INSTANCE, deleteDSReq).actionGet();
        DeleteComposableIndexTemplateAction.Request deleteTemplateRequest = new DeleteComposableIndexTemplateAction.Request("*");
        client().execute(DeleteComposableIndexTemplateAction.INSTANCE, deleteTemplateRequest).actionGet();
    }
    public void testAutoCreateV1TemplateNoDataStream() {
        Settings settings = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build();
        PutIndexTemplateRequest v1Request = new PutIndexTemplateRequest("logs-foo");
        v1Request.patterns(List.of("logs-foo*"));
        v1Request.settings(settings);
        v1Request.order(Integer.MAX_VALUE); 
        client().admin().indices().putTemplate(v1Request).actionGet();
        BulkRequest bulkRequest = new BulkRequest();
        bulkRequest.add(new IndexRequest("logs-foobar").opType(CREATE).source("{}", XContentType.JSON));
        BulkResponse bulkResponse = client().bulk(bulkRequest).actionGet();
        assertThat("bulk failures: " + Strings.toString(bulkResponse), bulkResponse.hasFailures(), is(false));
        GetDataStreamAction.Request getDataStreamRequest = new GetDataStreamAction.Request(new String[] { "*" });
        GetDataStreamAction.Response getDataStreamsResponse = client().execute(GetDataStreamAction.INSTANCE, getDataStreamRequest)
            .actionGet();
        assertThat(getDataStreamsResponse.getDataStreams(), hasSize(0));
        GetIndexResponse getIndexResponse = client().admin().indices().getIndex(new GetIndexRequest().indices("logs-foobar")).actionGet();
        assertThat(getIndexResponse.getIndices(), arrayWithSize(1));
        assertThat(getIndexResponse.getIndices(), hasItemInArray("logs-foobar"));
        assertThat(getIndexResponse.getSettings().get("logs-foobar").get(IndexMetadata.SETTING_NUMBER_OF_REPLICAS), equalTo("0"));
    }
    public void testCreatingDataStreamAndFirstBackingIndexExistsFails() throws Exception {
        String dataStreamName = "logs-foobar";
        long now = System.currentTimeMillis();
        String backingIndex = DataStream.getDefaultBackingIndexName(dataStreamName, 1, now);