### Elasticsearch Version

8.6.0, 8.7.0, 8.8.0, 8.9.0

### Installed Plugins

ESS default

### Java Version

ESS default

### OS Version

ESS default

### Problem Description

Our clusters hit continuously the following error on ESS

It is related to the number of shards per cluster `max_shards_in_cluster` that is calculated based on `max_shards_per_node` but is not correctly calculated, our value for `max_shards_per_node` is 10000. We have 10 data nodes, so we have configured more than 7000 shards per cluster for sure. No matter the value you put on `max_shards_per_node`, we cannot have more than 7000 shards in our clusters.

![image](https://github.com/elastic/elasticsearch/assets/5400788/b32b3025-6c49-4ea8-a793-3a3d8ff0d300)

```
      "shards_capacity" : {
        "status" : "Red",
        "symptom" : "Cluster is close to reaching the configured maximum number of shards for data nodes.",
        "details" : {
          "data" : {
            "max_shards_in_cluster" : 7000,
            "current_used_shards" : 9023
```

```
{
  "status": "green",
  "number_of_nodes": 10,
  "unassigned_shards": 0,
  "number_of_pending_tasks": 2,
  "number_of_in_flight_fetch": 0,
  "timed_out": false,
  "active_primary_shards": 5185,
  "task_max_waiting_in_queue_millis": 600,
  "cluster_name": "0000000000000000000000000",
  "relocating_shards": 0,
  "active_shards_percent_as_number": 100,
  "active_shards": 9753,
  "initializing_shards": 0,
  "number_of_data_nodes": 7,
  "delayed_unassigned_shards": 0
}
```

Probably related to https://github.com/elastic/elasticsearch/issues/91119

### Steps to Reproduce

* Deploy a cluster with Elastic Stack 8.7.0
* Create more than 7000 shards
* Change the value of `max_shards_per_node` to 5000
* Wait until the error appears again

### Logs (if relevant)

_No response_
server/src/main/java/org/elasticsearch/health/metadata/HealthMetadataService.java
}
    public static HealthMetadataService create(ClusterService clusterService) {
        HealthMetadataService healthMetadataService = new HealthMetadataService(clusterService);
        healthMetadataService.registerListeners();
        return healthMetadataService;
    }
    private void registerListeners() {
        if (this.enabled) {
            this.clusterService.addListener(clusterStateListener);
        }
        var clusterSettings = clusterService.getClusterSettings();
        Stream.of(
            CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING,
            CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_WATERMARK_SETTING,
            CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_FROZEN_WATERMARK_SETTING
        )
            .forEach(
                setting -> clusterSettings.addSettingsUpdateConsumer(
                    setting,
                    value -> updateOnSettingsUpdated(new UpdateDiskMetadata(setting.getKey(), value.getStringRep()))
                )
            );
        Stream.of(
            CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_FROZEN_MAX_HEADROOM_SETTING,
            CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_MAX_HEADROOM_SETTING,
            CLUSTER_ROUTING_ALLOCATION_DISK_FLOOD_STAGE_MAX_HEADROOM_SETTING
        )
            .forEach(
                setting -> clusterSettings.addSettingsUpdateConsumer(
                    setting,