Elasticsearch:统计和集群 API 中的分片数量不一致

Elasticsearch: Inconsistent number of shards in stats & cluster APIs

我将数据上传到我的单节点集群并将索引命名为 'gequest'。

当我从 http://localhost:9200/_cluster/stats?human&pretty 获取时,我得到:

 "cluster_name" : "elasticsearch",
  "status" : "yellow",
  "indices" : {
    "count" : 1,
    "shards" : {
      "total" : 5,
      "primaries" : 5,
      "replication" : 0.0,
      "index" : {
        "shards" : {
          "min" : 5,
          "max" : 5,
          "avg" : 5.0
        },
        "primaries" : {
          "min" : 5,
          "max" : 5,
          "avg" : 5.0
        },
        "replication" : {
          "min" : 0.0,
          "max" : 0.0,
          "avg" : 0.0
        }
      }
    }

当我在 http://localhost:9200/_stats?pretty=true

上执行 GET 时
"_shards" : {
    "total" : 10,
    "successful" : 5,
    "failed" : 0
  }

为什么两次报告的分片总数不一致?为什么总分片是 10 来自统计 API。如何跟踪其他 5 个?

从结果来看,您可能有一个 elasticsearch 节点 运行 并创建了一个具有默认值的索引(创建了 5 个分片和一个副本)。由于只有一个节点运行 elasticsearch无法在任何地方分配副本分片(elasticsearch永远不会在单个节点中分配同一个分片的主副本)。

_cluster/stats API 提供有关集群的信息,包括当前状态。从您的结果可以看出,集群状态为 "yellow",表明所有主分片都已分配,但并非所有副本都已分配 allocated/initialized。因此它仅将分配的分片显示为 5。

_stats API 提供有关您在集群中的索引的信息。它将提供有关索引将有多少个分片以及多少个副本的信息。由于您的索引总共需要 10 个分片(创建索引时指定的 5 个主分片和 5 个副本分片),统计信息包含总计 10 个、成功 5 个和失败 5 个(失败,因为无法在任何节点中分配)的信息。

使用http://localhost:9200/_cat/shards查看整体分片状态