How do I provision Elasticsearch with an index template?

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):

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.

No, there isn't, but #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, using something like this:

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).

1 Like

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