尝试将索引模板应用于 elasticsearch 时出现授权错误

Authorization error when trying to apply an index template to elasticsearch

所以我们在AWS中有一个elasticsearch服务运行,elasticsearch版本是7.8.0。我需要添加一个索引模板来限制在添加新索引时分配给新索引的分片数量。

我按照这个如何添加 index template 的例子得到了这个 非常 简单的模板:

PUT _index_template/shard_limitation
{
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    }
  }
}

当 运行 从 Kibana 的 Dev Tools 控制台发出此请求时,我收到以下错误:{"Message":"Your request: '/_index_template/shard_limitation' is not allowed."}。以及未授权 - 401 图标。我是 运行 使用 admin 用户执行此命令。

我在本地测试了它(elastic search 运行 在我的机器上),一切正常。知道为什么会发生这种情况吗?

解决方案:

正如@Ajinkya 所建议的那样,正确的做法是不要在模板 api 之前包含“_index”。实现我想要做的事情的正确方法是输入以下内容:

PUT _template/shard_limitation
{
  "index_patterns": ["some-pattern"],
  "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1
  }
}
AWS elasticsearch 可能不支持

'_index_template' 操作。您可以检查您的 AWS ES 版本 here

支持的操作

您仍然可以使用“_template”API添加索引模板

PUT _template/shard_limitation
{
  "index_patterns": ["test*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    }
  }
}