前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ElasticSearch(7.2.2)-es集群索引分⽚管理

ElasticSearch(7.2.2)-es集群索引分⽚管理

作者头像
cwl_java
发布2019-11-03 13:34:28
4930
发布2019-11-03 13:34:28
举报
文章被收录于专栏:cwl_Javacwl_Java

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。undefined本文链接:https://blog.csdn.net/weixin_42528266/article/details/102841384

简介:⼿把⼿教你索引分⽚管理

介绍

  • 分⽚(shard):因为ES是个分布式的搜索引擎, 所以索引通常都会分解成不同部分, ⽽这些分布在不同节点的数据就是分⽚. ES⾃动管理和组织分⽚, 并在必要的时候对分⽚数据进⾏再平衡分配, 所以⽤户基本上不⽤担⼼分⽚的处理细节。
  • 副本(replica):ES默认为⼀个索引创建1个主分⽚, 并分别为其创建⼀个副本分⽚. 也就是说每个索引都由1个主分⽚成本, ⽽每个主分⽚都相应的有⼀个copy.
  • Elastic search7.x之后,如果不指定索引分⽚,默认会创建1个主分⽚和⼀个副分⽚,⽽7.x版本之前的⽐如6.x版本,默认是5个主分⽚

创建索引(不指定分片数量)

代码语言:javascript
复制
PUT nba
{
	"mappings": {
		"properties": {
			"birthDay": {
				"type": "date"
			},
			"birthDayStr": {
				"type": "keyword"
			},
			"age": {
				"type": "integer"
			},
			"code": {
				"type": "text"
			},
			"country": {
				"type": "text"
			},
			"countryEn": {
				"type": "text"
			},
			"displayAffiliation": {
				"type": "text"
			},
			"displayName": {
				"type": "text"
			},
			"displayNameEn": {
				"type": "text"
			},
			"draft": {
				"type": "long"
			},
			"heightValue": {
				"type": "float"
			},
			"jerseyNo": {
				"type": "text"
			},
			"playYear": {
				"type": "long"
			},
			"playerId": {
				"type": "keyword"
			},
			"position": {
				"type": "text"
			},
			"schoolType": {
				"type": "text"
			},
			"teamCity": {
				"type": "text"
			},
			"teamCityEn": {
				"type": "text"
			},
			"teamConference": {
				"type": "keyword"
			},
			"teamConferenceEn": {
				"type": "keyword"
			},
			"teamName": {
				"type": "keyword"
			},
			"teamNameEn": {
				"type": "keyword"
			},
			"weight": {
				"type": "text"
			}
		}
	}
}

创建索引(指定分片数量)

  • settings
代码语言:javascript
复制
 "settings": {
	 "number_of_shards": 3,
	 "number_of_replicas": 1
 },
  • 创建索引
代码语言:javascript
复制
PUT nba
{
	"settings": {
		"number_of_shards": 3,
		"number_of_replicas": 1
	},
	"mappings": {
		"properties": {
			"birthDay": {
				"type": "date"
			},
			"birthDayStr": {
				"type": "keyword"
			},
			"age": {
				"type": "integer"
			},
			"code": {
				"type": "text"
			},
			"country": {
				"type": "text"
			},
			"countryEn": {
				"type": "text"
			},
			"displayAffiliation": {
				"type": "text"
			},
			"displayName": {
				"type": "text"
			},
			"displayNameEn": {
				"type": "text"
			},
			"draft": {
				"type": "long"
			},
			"heightValue": {
				"type": "float"
			},
			"jerseyNo": {
				"type": "text"
			},
			"playYear": {
				"type": "long"
			},
			"playerId": {
				"type": "keyword"
			},
			"position": {
				"type": "text"
			},
			"schoolType": {
				"type": "text"
			},
			"teamCity": {
				"type": "text"
			},
			"teamCityEn": {
				"type": "text"
			},
			"teamConference": {
				"type": "keyword"
			},
			"teamConferenceEn": {
				"type": "keyword"
			},
			"teamName": {
				"type": "keyword"
			},
			"teamNameEn": {
				"type": "keyword"
			},
			"weight": {
				"type": "text"
			}
		}
	}
}

索引分⽚分配

  • 分⽚分配到哪个节点是由ES⾃动管理的,如果某个节点挂了,那分⽚⼜会重新分配到别的节点上。
  • 在单机中,节点没有副分⽚,因为只有⼀个节点没必要⽣成副分⽚,⼀个节点挂点,副分⽚也会挂掉,完全是单故障,没有存在的意义。
  • 在集群中,同个分⽚它的主分⽚不会和它的副分⽚在同⼀个节点上,因为主分⽚和副分⽚在同个节点,节点挂了,副分⽚和主分机⼀样是挂了,不要把所有的鸡蛋都放在同个篮⼦⾥。
  • 可以⼿动移动分⽚,⽐如把某个分⽚移动从节点1移动到节点2。
  • 创建索引时指定的主分⽚数以后是⽆法修改的,所以主分⽚数的数量要根据项⽬决定,如果真的要增加主分⽚只能重建索引了。副分⽚数以后是可以修改的。

⼿动移动分片

代码语言:javascript
复制
POST /_cluster/reroute
{
	"commands": [{
		"move": {
			"index": "nba",
			"shard": 2,
			"from_node": "node-1",
			"to_node": "node-3"
		}
	}]
}

修改副分片数量

代码语言:javascript
复制
PUT /nba/_settings
{
	 "number_of_replicas": 2
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-10-31 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 介绍
  • 创建索引(不指定分片数量)
  • 创建索引(指定分片数量)
  • 索引分⽚分配
  • ⼿动移动分片
  • 修改副分片数量
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档