Python 官方文档:入门教程 => 点击学习
目录正文设置为只读正文 将索引设置为只读可能听起来很奇怪,但在 elasticsearch 中执行此类操作是可能的。想象一下这样一种情况,你特别需要限制对索引的写入操作,无论是维护
将索引设置为只读可能听起来很奇怪,但在 elasticsearch 中执行此类操作是可能的。想象一下这样一种情况,你特别需要限制对索引的写入操作,无论是维护、业务规则还是任何其他原因。让我们学习如何将索引配置为已读以及如何撤消操作。
我们先使用如下的命令来创建一个叫做 test 的索引:
PUT test/_doc/1
{
"content": "I am xiaoguo from Elastic"
}
要进行此更改,我们需要更新索引设置。 下面的命令将使索引成为只读的。
PUT /test/_settings
{
"index": {
"blocks": {
"write": true
}
}
}
执行完上面的命令后,我们可以再接着创建一个如下的一个文档:
PUT test/_doc/2
{
"content": "I am an evangelist as well"
}
我们可以看到如下的一个响应:
{
"error": {
"root_cause": [
{
"type": "cluster_block_exception",
"reason": "index [test] blocked by: [FORBIDDEN/8/index write (api)];"
}
],
"type": "cluster_block_exception",
"reason": "index [test] blocked by: [FORBIDDEN/8/index write (api)];"
},
"status": 403
}
要恢复只需将状态从 true 更改为 false。我们试着运行如下的命令:
PUT /test/_settings
{
"index": {
"blocks": {
"write": false
}
}
}
我们再次写入我们想要的文档。我们可以看到这次的写入是成功的:
PUT test/_doc/2
{
"content": "I am an evangelist as well"
}
上面的响应为:
{
"_index": "test",
"_id": "2",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
希望这个能帮助到你。
以上就是详解Elasticsearch如何把一个索引变为只读的详细内容,更多关于Elasticsearch索引变只读的资料请关注编程网其它相关文章!
--结束END--
本文标题: 详解Elasticsearch如何把一个索引变为只读
本文链接: https://www.lsjlt.com/news/194370.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0