具体操作可以查看官方文档
https://www.elastic.co/guide/en/elasticsearch/reference/7.5/indices.html>
官方2版本的中文文档
https://www.elastic.co/guide/cn/elasticsearch/guide/current/index-settings.html
Ⅰ: 索引初始化
#新建一个honglvliyu的索引,索引分片数量为5,索引副本数量为1
PUT honglvliyu
{
"settings": {
"index":{
"number_of_shards":5,
"number_of_replicas":1
}
}
}
--
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "honglvliyu"
}
'''
number_of_shards
每个索引的主分片数,默认值是 5 。这个配置在索引创建后不能修改。
number_of_replicas
每个主分片的副本数,默认值是 1 。对于活动的索引库,这个配置可以随时修改。
'''
Ⅱ: 查询索引配置
#获取honglvliyu索引的配置信息
GET honglvliyu/_settings
--
{
"honglvliyu": {
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "5",
"provided_name": "honglvliyu",
"creation_date": "1700206346503",
"number_of_replicas": "1",
"uuid": "54QlZLFoRUmelv82cdIxWQ",
"version": {
"created": "8500003"
}
}
}
}
}
#获取所有索引的配置信息
GET _all/_settings
#同上
GET _settings
#获取Cat和lqz2索引的配置信息
GET cat,honglvliyu/_settings
--
{
"honglvliyu": {
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "5",
"provided_name": "honglvliyu",
"creation_date": "1700206346503",
"number_of_replicas": "1",
"uuid": "54QlZLFoRUmelv82cdIxWQ",
"version": {
"created": "8500003"
}
}
}
},
"cat": {
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "5",
"provided_name": "cat",
"creation_date": "1700206616250",
"number_of_replicas": "1",
"uuid": "tU6Ph0pwRUSppmmdEP7KNw",
"version": {
"created": "8500003"
}
}
}
}
}
Ⅲ: 更新索引
#修改索引副本数量为2
PUT honglvliyu/_settings
{
"number_of_replicas": 2
}
--
{
"acknowledged": true
}
#如遇到报错:cluster_block_exception,因为
#这是由于ES新节点的数据目录data存储空间不足,导致从master主节点接收同步数据的时候失败
#此时ES集群为了保护数据,会自动把索引分片index置为只读read-only
PUT _all/_settings
{
"index": {
"blocks": {
"read_only_allow_delete": false
}
}
}
--
{
"acknowledged": true
}
Ⅳ: 删除索引
#删除lqz索引
DELETE honglvliyu
One comment
怎么收藏这篇文章?