You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elasticsearch如何查询主分片所在运行节点?含分片配置场景

Hey there! Let's break down your Elasticsearch questions clearly and practically:

问题1:如何查询Elasticsearch中主分片的运行节点名称?

The easiest way to get this info is using the handy _cat/shards API—it’s built for human-readable cluster shard details. Just run this command in Kibana Dev Tools or via curl:

GET _cat/shards?v

In the output, look for rows where the prirep column shows a p (that’s the marker for primary shards). The last column (node) will display the exact name of the node where that primary shard is running.

If you want to cut straight to primary shards without extra noise, add a filter to the query:

GET _cat/shards?v&h=index,shard,prirep,node&prirep=p

This trims the output to only the columns you care about: index name, shard ID, primary status, and the hosting node.

问题2:假设某Elasticsearch索引拥有5个主分片,每个主分片配置2个副本分片,集群当前有3个活跃节点,如何查询各主分片分别位于哪个节点?

For a specific index, narrow down the _cat/shards API to target just that index. Replace <your-index-name> with your actual index’s name:

GET _cat/shards/<your-index-name>?v

Focus on rows with prirep=p—you’ll see 5 entries (one for each primary shard, IDs 0-4), and the node column will tell you which of your 3 cluster nodes each primary is hosted on.

If you prefer structured JSON output (perfect for scripting), use the _cluster/state API with a filter to pull only primary shard routing data for your index:

GET _cluster/state?filter_path=routing_table.indices.<your-index-name>.shards.*.primary

A simplified response will look like this:

{
  "routing_table": {
    "indices": {
      "your-index-name": {
        "shards": {
          "0": {
            "primary": {
              "node": "node-1"
            }
          },
          "1": {
            "primary": {
              "node": "node-2"
            }
          },
          // ... shards 2-4 will follow with their respective node assignments
        }
      }
    }
  }
}

This gives you a clean, machine-readable view of exactly which node each primary shard is assigned to.


内容的提问来源于stack exchange,提问作者Klaus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:13:24