Files
elasticsearch/docs/07.分片和副本.md
2022-12-01 17:18:29 +08:00

31 lines
1.8 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 分片shard
Elasticsearch集群允许系统存储的数据量超过单机容量实现这一目标引入分片策略shard。
在一个索引index中数据document被分片处理sharding到多个分片上。Elasticsearch屏蔽了管理分片的复杂性使得多个分片呈现出一个大索引的样子。
## 副本replica
为了提升访问压力过大是单机无法处理所有请求的问题Elasticsearch集群引入了副本策略replica。
副本策略对index中的每个分片创建冗余的副本处理查询时可以把这些副本当做主分片来对待primary shard此外副本策略提供了高可用和数据安全的保障当分片所在的机器宕机Elasticsearch可以使用其副本进行恢复从而避免数据丢失。
副本的作用如下:
1. 提高系统容错性
        当分片所在的机器宕机时Elasticsearch可以使用其副本进行恢复从而避免数据丢失。
2. 提高ES查询效率
        处理查询时ES会把副本分片和主分片公平对待将查询请求负载均衡到副本分片和主分片。
副本分片是越多越好吗?
答案当然是 no ,原因有以下两点:
1多个 replica 可以提升搜索操作的吞吐量和性能,但是如果只是在相同节点数目的集群上增加更多的副本分片并不能提高性能,因为每个分片从节点上获得的资源会变少,这个时候你就需要增加更多的硬件资源来提升吞吐量。
2更多的副本分片数提高了数据冗余量保证了数据的完整性但是根据上边主副分片之间的交互原理可知分片间的数据同步会占用一定的网络带宽影响效率所以索引的分片数和副本数也不是越多越好。