# 【參數說明】enable_for_single_data_node

下面我會用 **最清楚、最貼近你現在 ES 架構的方式** 解釋  
`enable_for_single_data_node` 是什麼、什麼時候要開/關、會影響什麼。

---

# ⭐ **1. enable\_for\_single\_data\_node 是什麼？**

這是一個 **Elasticsearch 控制 Watermark 是否要啟用於單節點（Single Data Node）環境的設定**。

完整參數名稱：

```
cluster.routing.allocation.disk.watermark.enable_for_single_data_node

```

它的作用：

> **如果你的 Elasticsearch 只有 1 台 node（單機 ES），是否也要套用磁碟 watermark 限制？**

---

# ⭐ **2. 為什麼會有這個設定？**

因為 Elasticsearch 原本的 watermark 行為（low / high / flood\_stage）是為 **多節點 cluster** 設計的。

但如果你是：

✔ 單機 Elasticsearch  
✔ 沒有第二台 node 可以搬 shard

那就會出現很尷尬的情況：

> 一旦磁碟超過 watermark（例如 high 90%）  
> ES 想搬 shard……  
> 但根本沒有其他 node 能搬  
> 然後 ES 就會把 shard 標成 UNASSIGNED  
> 或直接鎖住 index（Read-only）

這在單機 ES 是「不合理且災難級別的行為」。

所以 ES 才加入這個參數：

---

# ⭐ **3. 功能用一句話總結**

### 👉 如果設定成 `true`

即使你只有 1 台 Elasticsearch，也會啟用 watermark（high / flood\_stage 等）。

### 👉 如果設定成 `false`

單機 ES **忽略 high watermark（不阻止分配 shard）**  
但 **flood\_stage（95%）還是會強制生效**（避免你把磁碟寫爆）

---

# ⭐ **4. 預設值是？（重點）**

版本差異：

<table id="bkmrk-elasticsearch-%E7%89%88%E6%9C%AC-%E9%A0%90%E8%A8%AD%E5%80%BC"><thead><tr><th>Elasticsearch 版本</th><th>預設值</th><th>說明</th></tr></thead><tbody><tr><td>**7.x**</td><td>`false`</td><td>單機不啟用 high watermark</td></tr><tr><td>**8.x**</td><td>`true`</td><td>單機也啟用完整 watermark 機制</td></tr></tbody></table>

如果你看到是 `true`，通常代表：

✔ 你是 ES 8.x  
✔ 或你用了 hot/warm/cold/frozen 層級  
✔ 或你用到 searchable snapshots

---

# ⭐ **5. 那你應該設 true 還是 false？（最重要）**

### ✔ 如果你是 **單機 Elasticsearch（只有 1 台）**

我建議：

```
cluster.routing.allocation.disk.watermark.enable_for_single_data_node": false

```

理由：

- 避免 high watermark（90%）直接禁止 shard 分配
- 避免 index 提前 read-only
- 避免 cluster 假性「red/yellow」狀態
- 單機沒必要用 cluster-style routing

> 但 flood\_stage 仍然會保護你避免磁碟爆滿。

這是 **單機 ES 正常、合理、安全** 的設定。

---

### ✔ 如果你是 **真正的多節點 cluster（&gt;= 2 data node）**

你應該保留 `true`  
讓 ES 正常做 shard relocation。

---

# ⭐ **6. 單行解釋（你可以放到備忘）：**

##### `enable_for_single_data_node = false` → 單機不要限制太多，不要亂搬 shard

##### `enable_for_single_data_node = true` → 多機需要完整 watermark 保護

---

# ⭐ 7. 你現在的情況（結論）

根據你前面截圖：  
你有 frozen、watermark、read-only、filebeat 等狀況

**高度機率你是單機 or 少數機器的 ES**

所以：

```
"cluster.routing.allocation.disk.watermark.enable_for_single_data_node": "true"

```

會讓 ES：

❌ 必須搬 shard  
❌ 但沒地方搬  
❌ 於是高水位直接阻斷分配  
❌ 然後 ES 把 index 鎖成 read-only  
❌ 造成 filebeat 錯誤

你就會看到「設定無效」、「read-only-allow-delete」、「flood-stage」等問題。

---

# ⭐ 給你正確的單機 ES 設定模板（最穩定、不會鎖 index）

```bash
PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.disk.watermark.low": "10gb",
    "cluster.routing.allocation.disk.watermark.high": "5gb",
    "cluster.routing.allocation.disk.watermark.flood_stage": "2gb",

    "cluster.routing.allocation.disk.watermark.enable_for_single_data_node": "false",

    "cluster.routing.allocation.disk.watermark.low.frozen": null,
    "cluster.routing.allocation.disk.watermark.high.frozen": null,
    "cluster.routing.allocation.disk.watermark.flood_stage.frozen": null,
    "cluster.routing.allocation.disk.watermark.low.frozen.max_headroom": null,
    "cluster.routing.allocation.disk.watermark.high.frozen.max_headroom": null,
    "cluster.routing.allocation.disk.watermark.flood_stage.frozen.max_headroom": null
  }
}

```

---

# 如果你願意

貼下面這段，我可以直接判斷你該用 `true` 或 `false`：

```
GET _cat/nodes?v

```

或

```
GET _cluster/settings?include_defaults=true&pretty

```

我可以直接比對你的 cluster 架構（單機/多機）給你最適設定。