elasticsearch 为什么Elasticsearch允许我在单节点集群中索引无法满足仲裁要求的文档?,elasticsearch,indexing,quorum,elasticsearch,Indexing,Quorum" /> elasticsearch 为什么Elasticsearch允许我在单节点集群中索引无法满足仲裁要求的文档?,elasticsearch,indexing,quorum,elasticsearch,Indexing,Quorum" />

elasticsearch 为什么Elasticsearch允许我在单节点集群中索引无法满足仲裁要求的文档?

elasticsearch 为什么Elasticsearch允许我在单节点集群中索引无法满足仲裁要求的文档?,elasticsearch,indexing,quorum,elasticsearch,Indexing,Quorum,发件人: 请注意,复制副本的数量是在索引设置中指定的复制副本数量,而不是当前活动的复制副本数量。如果指定索引应具有三个副本,则仲裁如下: int((主副本+3副本)/2)+1=3 但是,如果只启动两个节点,则活动碎片副本将不足,无法满足仲裁要求,并且您将无法索引或删除任何文档 curl -X DELETE http://localhost:9200/a/?pretty curl -X PUT -siH 'Content-Type: application/json' \ http://

发件人:

请注意,复制副本的数量是在索引设置中指定的复制副本数量,而不是当前活动的复制副本数量。如果指定索引应具有三个副本,则仲裁如下:

int((主副本+3副本)/2)+1=3

但是,如果只启动两个节点,则活动碎片副本将不足,无法满足仲裁要求,并且您将无法索引或删除任何文档

curl -X DELETE http://localhost:9200/a/?pretty
curl -X PUT -siH 'Content-Type: application/json' \
     http://localhost:9200/a?pretty -d '{

    "settings": {
        "number_of_replicas": 3
    }
}'
curl -sH 'Content-Type: application/json' -X PUT http://localhost:9200/a/a/1?pretty -d '{"a": "a"}'
curl -si http://localhost:9200/_cluster/health?pretty
curl -si http://localhost:9200/a/a/1?pretty
我在单节点集群上运行了以下命令,并且我能够成功地为文档编制索引,尽管上面的数学表明我不应该能够为文档编制索引

curl -X DELETE http://localhost:9200/a/?pretty
curl -X PUT -siH 'Content-Type: application/json' \
     http://localhost:9200/a?pretty -d '{

    "settings": {
        "number_of_replicas": 3
    }
}'
curl -sH 'Content-Type: application/json' -X PUT http://localhost:9200/a/a/1?pretty -d '{"a": "a"}'
curl -si http://localhost:9200/_cluster/health?pretty
curl -si http://localhost:9200/a/a/1?pretty
以下是输出:

$ curl -X PUT -siH 'Content-Type: application/json' \
     http://localhost:9200/a?pretty -d '{

    "settings": {
        "number_of_replicas": 3
    }
}'
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 77

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "a"
}

$ curl -sH 'Content-Type: application/json' -X PUT http://localhost:9200/a/a/1?pretty -d '{"a": "a"}'
{
  "_index" : "a",
  "_type" : "a",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 4,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

$ curl -si http://localhost:9200/_cluster/health?pretty
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 468

{
  "cluster_name" : "docker-cluster",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 5,
  "active_shards" : 5,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 15,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 25.0
}

$ curl -si http://localhost:9200/a/a/1?pretty
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 124

{
  "_index" : "a",
  "_type" : "a",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "a" : "a"
  }
}

即使我已将索引配置为具有3个副本碎片,并且数学表明我必须至少具有3个节点,但我如何能够仅使用1个节点为文档编制索引?

这是ES 2.x中的旧定额规则。从ES 5.x开始,写入一致性检查已稍微更改,黄色群集(即群集将分配所有主碎片)将通过写入操作的一致性检查,并允许您索引和删除文档

curl -X DELETE http://localhost:9200/a/?pretty
curl -X PUT -siH 'Content-Type: application/json' \
     http://localhost:9200/a?pretty -d '{

    "settings": {
        "number_of_replicas": 3
    }
}'
curl -sH 'Content-Type: application/json' -X PUT http://localhost:9200/a/a/1?pretty -d '{"a": "a"}'
curl -si http://localhost:9200/_cluster/health?pretty
curl -si http://localhost:9200/a/a/1?pretty
现在,决定是否可以进行写入的方法是在索引操作中使用
wait\u for\u active\u shards
参数。默认情况下,如果所有主碎片都已启动,则将允许索引操作。您可以通过指定您希望在授权索引操作之前处于活动状态的碎片的数量来覆盖该设置,例如,在您的情况下,
wait\u for_active\u shard=all
,这相当于
wait\u for_active\u shard=4
(4=1个主副本+3个副本)。如果您想要与以前相同的仲裁规则,请指定
wait\u for\u active\u shards=3


有关更多信息,请参见和

操作?@keety elasticsearch版本6.1.3中测试使用的elasticsearch版本。