Search code examples
kibanaaws-elasticsearch

Authorization error when trying to apply an index template to elasticsearch


so we have an elastic search service running in AWS, the elasticsearch version is 7.8.0. And I need to add an index template to limit the amount of shards that are allocated to new indices when they are added.

I followed this example of how to add an index template and got this very simple template:

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

When running this request from the inside Kibana's Dev Tools console I get the following error: {"Message":"Your request: '/_index_template/shard_limitation' is not allowed."}. As well as an Unauthorized - 401 icon. I'm running this command with the admin user.

I tested it locally (elastic search running on my machine) and it all works fine. Any idea why this might happen?

SOLUTION:

As was suggested by @Ajinkya, the correct way to do this is to not include the "_index" before the template api. The correct way to achieve what I was trying to do is to type the following:

PUT _template/shard_limitation
{
  "index_patterns": ["some-pattern"],
  "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1
  }
}

Solution

  • '_index_template' operation might not be supported in AWS elasticsearch. You can check supported operations for your AWS ES version here

    You can still use '_template' API to add index template

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