概述
- Elasticsearch是一个分布式的搜索引擎,索引的数据也是分成若干部分,分布在不同的服务器节点中,
一个索引的数据在不同的集群节点上可能有两种状态。
分片(Shard)
分布在不同服务器节点中的索引数据,就是分片(Shard)。
- Elasticsearch会自动管理分片,如果发现分片分布不均衡,就会自动迁移
一个索引(index)由多个shard(分片)组成,而分片是分布在不同的服务器上的。
副本
- 为了对Elasticsearch的分片进行容错,假设某个节点不可用,会导致整个索引库都将不可用。
- 所以,需要对分片进行副本容错。每一个分片都会有对应的副本。
- 每个分片都会有一个Primary Shard(主分片),也会有若干个Replica Shard(副本分片)
- Primary Shard和Replica Shard不在同一个节点上。
主分片(Primary Shard)
副本分片(Replica Shard)
```http // 创建指定分片数量、副本数量的索引 PUT /job_idx_shard_temp { “mappings”:{ “properties”:{ “id”:{“type”:”long”,”store”:true}, “area”:{“type”:”keyword”,”store”:true}, “exp”:{“type”:”keyword”,”store”:true}, “edu”:{“type”:”keyword”,”store”:true}, “salary”:{“type”:”keyword”,”store”:true}, “job_type”:{“type”:”keyword”,”store”:true}, “cmp”:{“type”:”keyword”,”store”:true}, “pv”:{“type”:”keyword”,”store”:true}, “title”:{“type”:”text”,”store”:true}, “jd”:{“type”:”text”}
} }, “settings”:{ “number_of_shards”:3, “number_of_replicas”:2 } }
// 查看分片、主分片、副本分片 GET /_cat/indices?v ```