# How do I provision Elasticsearch with an index template?

**URL:** https://discuss.elastic.co/t/how-do-i-provision-elasticsearch-with-an-index-template/162984
**Category:** Elasticsearch
**Created:** [January 4, 2019, 3:47pm UTC](https://discuss.elastic.co/t/how-do-i-provision-elasticsearch-with-an-index-template/162984 "2019-01-04T15:47:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mattskone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattskone/32/39423_2.png) [@mattskone](https://discuss.elastic.co/u/mattskone)
#### Post date: [January 4, 2019, 3:47pm UTC](https://discuss.elastic.co/t/how-do-i-provision-elasticsearch-with-an-index-template/162984/1 "2019-01-04T15:47:47Z")

</div>

I'm supporting an ELK stack with version 6.3.x of all components. I want to reduce the sharding factor of all indices from the 5 (default) to 3 (the number of data nodes in the ES cluster). From reading the documentation and many threads in this forum, it seems clear that the way to do this is to create an index template.

For example (ref [this thread](https://discuss.elastic.co/t/how-change-default-number-of-shards/117985)):

```
POST _template/default
{
  "index_patterns": ["*"],
  "settings": {
    "number_of_shards": "3"
  }
}

```

Great, got it.

However, this requires me to wait for Elasticsearch to be up and healthy before I `POST` this template to the API. From an automation standpoint - to take the human out of the loop - it looks like I have to write a process to wait for the cluster to be healthy, then `POST` the template.

Is there no way to provision this template automatically at cluster creation time? Is there perhaps a `/templates` directory where I can drop template files that ES will read on startup? I must be missing something, because this seems like it would be a common use case for automated provisioning.

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [January 5, 2019, 9:39am UTC](https://discuss.elastic.co/t/how-do-i-provision-elasticsearch-with-an-index-template/162984/2 "2019-01-05T09:39:17Z")

</div>

> [@mattskone](#):
>
> Is there no way to provision this template automatically at cluster creation time? Is there perhaps a `/templates` directory where I can drop template files that ES will read on startup?

No, there isn't, but [#35885](https://github.com/elastic/elasticsearch/issues/35885) is a similar request so I've linked this post there.

However, waiting for the cluster to the healthy is already a feature of the [cluster health API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-health.html), using something like this:

```auto
GET _cluster/health?wait_for_nodes=<N>&timeout=1d

```

This'll only return once a master has been elected and `<N>` nodes have joined the cluster (or fail after a day, but hopefully you've already considered the provisioning to have failed by this point).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [February 2, 2019, 9:39am UTC](https://discuss.elastic.co/t/how-do-i-provision-elasticsearch-with-an-index-template/162984/3 "2019-02-02T09:39:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
