简体   繁体   English

在Elasticsearch中复制

[英]Replication in Elasticsearch

I have created a cluster with one master node and two data nodes. 我创建了一个具有一个主节点和两个数据节点的集群。 I need to know how replicas are created once I index a document in master node. 我需要知道在主节点中建立索引后如何创建副本。 Is there a way to find out if my replicas are successfully created or not? 有没有办法找出我的副本是否成功创建? Also, how do I shut down my master node and check if my replicas are accessible through my data node? 另外,如何关闭主节点并检查副本是否可以通过数据节点访问?

In Elasticsearch, the master nodes don't hold any data at all. 在Elasticsearch中,主节点根本不保存任何数据。 It is not the same concept as in a master/slave database. 它与主/从数据库中的概念不同。 In ES, you cannot shutdown the master and expect the data node to work. 在ES中,您无法关闭主服务器并期望数据节点正常工作。 If you shut down your single master node, your cluster goes red and nothing works anymore. 如果关闭单个主节点,则群集将变为红色,并且不再起作用。

Primary and replica shards are all stored on the data nodes only . 主分片和副本分片仅存储在数据节点上 Your indexes are partitioned into primary shards which will be balanced over all data nodes of your cluster. 您的索引被划分为主分区,这些分区将在群集的所有数据节点之间保持平衡。 If you decide to have replica shards, the primary shards will be copied and balanced over the data nodes the same way. 如果决定使用副本分片,则将以相同的方式在数据节点上复制并平衡主分片。

When you index a document, you typically send it to the data nodes, the document will be indexed in the primary shard and then replicated into the corresponding replica shard. 对文档建立索引时,通常将其发送到数据节点,该文档将在主分片中建立索引,然后复制到相应的副本分片中。

Once you have indexed a document you can check whether both the primary and replica shards contain that document using the preference parameter in your search, eg 一旦为文档建立索引,就可以使用搜索中的preference参数来检查主分片和副本分片是否都包含该文档,例如

This will only search the primary shards 这只会搜索主要碎片

GET my-index/_search?preference=_primary

This will only search the replica shards 这只会搜索副本碎片

GET my-index/_search?preference=_replica

If the indexing operation was successful, both searches should return exactly the same results. 如果索引操作成功,则两次搜索应返回完全相同的结果。

Note that the preference parameter has been deprecated in 6.1 and will be removed in 7 as its usage is discouraged . 请注意, preference参数已在6.1中弃用,并且由于不鼓励使用 ,将在7中将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM