elasticsearch 未创建副本分片

elasticsearch 未创建副本分片

我花了两天时间思考这个问题。我设置了一个由两个节点组成的 elasticsearch 集群。每个节点的配置都很简单:

node.name: "server1"
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: 192.168.1.212,192.168.1.213
index.store.compress.stored: True
index.store.compress.tv: True
index.number_of_shards: 5
compress.default.type: lzf
cluster.name: mycluster
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.timeout: 60
index.number_of_replicas: 1

集群节点“看到”彼此,并生成了预期的分片,但没有生成副本。当我使用“head”插件(elasticsearch 的 Web UI)时,我只能看到主分片,而看不到副本。这也从 elasticsearch 的状态中得到了证实:

 curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
 {
  "cluster_name" : "server1",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 10,
  "active_shards" : 10,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0
}

另外我在 elasticsearch 的运行设置中注意到的另外一件事是副本设置为 0:

curl -XGET 'http://localhost:9200/_settings?pretty=true'
{
  "date" : {
    "settings" : {
      "index" : {
        "refresh_interval" : "1s",
        "number_of_shards" : "5",
        "creation_date" : "1447756143035",
        "store" : {
          "type" : "fs"
        },
        "uuid" : "mpVS_BB9R0WvoF0h8pFVfQ",
        "version" : {
          "created" : "1040299"
        },
        "number_of_replicas" : "0"
      }
    }
  },
  "scores" : {
    "settings" : {
      "index" : {
        "refresh_interval" : "1s",
        "number_of_shards" : "5",
        "creation_date" : "1447756144186",
        "store" : {
          "type" : "fs"
        },
        "uuid" : "KUlfG4UhQfmMP1L3xQiJOQ",
        "version" : {
          "created" : "1040299"
        },
        "number_of_replicas" : "0"
      }
    }
  }
}

知道为什么不创建副本吗?

答案1

根据最后一条命令的输出,您的两个索引没有副本,因为您没有告诉它们。

您需要更新索引设置,将其更改"number_of_replicas"为您想要的副本数量。

更新索引设置ES 文档的页面上有一个完全相同的示例。

这将改变全部索引为 1 个副本:

curl -XPUT 'localhost:9200/_settings' -d '
{
  "index" : {
    "number_of_replicas" : 1
  }
}'

这将改变只是将索引scores设置为 4 个副本:

curl -XPUT 'localhost:9200/scores/_settings' -d '
{
  "index" : {
    "number_of_replicas" : 4
  }
}'

相关内容