如何设置Elasticsearch索引为只读?
- By : Will
- Category : Elastic Stack
Elastic Stack
1 前言
一个问题,一篇文章,一出故事。
基于集群性能的需求,笔者想通过将旧索切换到温暖阶段,设置为只读并将其缩减为单个分片。
本章将完成单个索引的只读操作,至于缩减分片数量笔者将在另外一个章节里面整理归纳。
2 最佳实践
2.1 查看修改前的索引的设置
GET /postfix-2024.11.30/_settings
可见如下显示,
{
"postfix-2024.11.30": {
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "postfix-2024.11.30",
"creation_date": "1732924802036",
"number_of_replicas": "0",
"uuid": "kwP_bvB_RK-UssUjYahIvA",
"version": {
"created": "8505000"
}
}
}
}
}
注:以上“postfix-2024.11.29”为索引的名称
2.2 设置索引为只读
PUT /postfix-2024.11.30/_settings
{
"index": {
"blocks": {
"write": true
}
}
}
2.3 查看修改后的索引的设置
{
"postfix-2024.11.30": {
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"blocks": {
"write": "true"
},
"provided_name": "postfix-2024.11.30",
"creation_date": "1732924802036",
"number_of_replicas": "0",
"uuid": "kwP_bvB_RK-UssUjYahIvA",
"version": {
"created": "8505000"
}
}
}
}
}
可见如下显示,其中'”write”: “true”‘表示只读,不现实为默认值'”write”: “false”‘
参阅文档
===================
没有评论