# Elastic Template to manage Settings

**URL:** https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502
**Category:** Elasticsearch
**Created:** [September 14, 2016, 12:16pm UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502 "2016-09-14T12:16:41Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![tgdesrochers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tgdesrochers/32/51322_2.png) [@tgdesrochers](https://discuss.elastic.co/u/tgdesrochers)
#### Post date: [September 14, 2016, 12:16pm UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/1 "2016-09-14T12:16:41Z")

</div>

I am trying to set shards, replicas, and shard allocation utilizing a template. I thought I had everything working but newly created indices are not getting the index template applied.

my template is:

```
{
  "order": 2,
  "template": "*",
  "settings": {
    "index": {
      "index": {
        "routing": {
          "allocation": {
            "require": {
              "box_type": "hot"
            }
          }
        }
      },
      "refresh_interval": "5s",
      "number_of_shards": "10",
      "number_of_replicas": "1"
    }
  },
  "mappings": {},
  "aliases": {}
}
```

My thought was this would match all templates that are in elastic. So if any new index were created this template would be applied. I checked all existing templates and there is one Order 0 and one Order 2, so I thought this being Order 3 would be the last applied and override any other of these settings in the previous templates.

My issue is it is not working. Can someone please advise where my mistake is being made?

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [September 14, 2016, 2:16pm UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/2 "2016-09-14T14:16:51Z")

</div>

Hi,

your assumption that templates get applied with increasing order. What exactly isn't working as expected? What do the other templates look like and which setting doesn't turn out as expected when you create a new index?

---

<div class="post-metadata">

### Author: ![tgdesrochers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tgdesrochers/32/51322_2.png) [@tgdesrochers](https://discuss.elastic.co/u/tgdesrochers)
#### Post date: [September 14, 2016, 4:43pm UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/3 "2016-09-14T16:43:23Z")

</div>

sorry. My assumption that the templates in a higher order get applied last doesnt' seem to apply.

The setting of routing.allocation.require doesn't get set nor do shards or replicas. I dont' have any templates with a higher order. I have the basic logstash template for logstash-\* indices but non e of my indices follow that pattern. When new indices get created they are going to nodes with box\_type set to cold and they don't have the correct number of shards or replicas set.

I'm happy to share most any data I can to help. Just let me know whats needed

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [September 15, 2016, 9:23am UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/4 "2016-09-15T09:23:52Z")

</div>

Hi,

to debug this you could add something unique to each of your templates (e.g. a bogus mapping with a unique name for each template you have). Then you create a new index and check which of these mappings are there. This way you know which templates are appied for this index name pattern. Remove those mappings again and add a setting with a different value for each effective template. Rinse and repeat, to see which template gets applied last.  
If this doesn't work, could you try to set up a minimal example of where the settings overwrite doesn't work as expected (also add the Elasticsearch version you are using)?

---

<div class="post-metadata">

### Author: ![tgdesrochers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tgdesrochers/32/51322_2.png) [@tgdesrochers](https://discuss.elastic.co/u/tgdesrochers)
#### Post date: [September 15, 2016, 9:55am UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/5 "2016-09-15T09:55:18Z")

</div>

Thank you. I will try that. I am on ES 2.3.3.

---

<div class="post-metadata">

### Author: ![tgdesrochers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tgdesrochers/32/51322_2.png) [@tgdesrochers](https://discuss.elastic.co/u/tgdesrochers)
#### Post date: [September 20, 2016, 10:37am UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/6 "2016-09-20T10:37:41Z")

</div>

So still no luck. I can see the setting in the index setting section. I see the correct setting for:

```
"settings": {
    "index": {
      "index": {
        "routing": {
          "allocation": {
            "require": {
              "box_type": "hot"
            }
          }
        }
      },
      "refresh_interval": "5s",
      "number_of_shards": "10",
      "number_of_replicas": "1"
    }
```

But it seems elastic is ignoring the setting. Why would this happen. If the setting is visible when I view "GET /index-name/\_settings", then why would elastic not use it. When I run curator and tell it :  
curator --loglevel DEBUG --timeout 3600 --host 10.1.55.2 allocation --rule box\_type=hot indices --prefix index-name

it applies a second instance of the setting and then data gets allocated appropriately.

I created a bash script to run every day to reallocate the shards but I wouldn't think that should be necessary if I am using index templates to create the right settings.

Thanks

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [September 20, 2016, 10:55am UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/7 "2016-09-20T10:55:32Z")

</div>

Hi,  
so do I understand this correctly, this is no longer an issue with templates and the overwrite order but more a question about allocation? Can you specify again what your scenario looks like, i.e. what your expected behaviour for this setting is and what you see instead. Also how many nodes do you have?

---

<div class="post-metadata">

### Author: ![tgdesrochers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tgdesrochers/32/51322_2.png) [@tgdesrochers](https://discuss.elastic.co/u/tgdesrochers)
#### Post date: [September 20, 2016, 11:09am UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/8 "2016-09-20T11:09:33Z")

</div>

The question is still regarding templates and why when setting settings through a template they get applied to the index but not necessarily read by ES.

My setup:  
ES 2.3.3  
12 Data Nodes 64 GB RAM, 6TB HDD 24 core (box\_type: hot)  
3 Data Nodes 64 GB RAM, A LOT of storage (spinning) (box\_type: cold)  
5 Client Nodes 32 GB RAM 24 core

What my scenario is:  
I have data indexed daily, I want to age the data at 30 day from node box\_type: hot to node box\_type: cold. I have a template set up to match all indices '\*' that creates the setting:

```
"settings": {
    "index": {
      "index": {
        "routing": {
          "allocation": {
            "require": {
              "box_type": "hot"
            }
          }
        }
      },
      "refresh_interval": "5s",
      "number_of_shards": "10",
      "number_of_replicas": "1"
    }
```

I want this to set my shards/replicas, along with my routing allocation.

What do I see happening:  
When the index gets created first the primary shards do not allocate, I receive a red cluster at midnight UTC time when net indices are created because all primary shards become unalloocated. When I look at the index setting of the unallocated shards I can see the setting are set in one index but not the other 3 but elastic seems to ignore the setting on the one index.

When I run curator to set the routing allocation I can see a second setting for shards, replicas, and routing allocation on the first index, and I can see the settings get applied a first time on the other indices. After a few seconds I get a green cluster because the settings are applied and routing happens according to the settings.

I don't know why the template is seeming ignored for 3 of my 4 indices. I don't know why it is applied on one index but not used by elastic. My goal would be to have my indices created with box\_type set to hot and replicas and shards set appropriately and my cluster stay green the entire time so I am not left with unallocated shards.

As stated I have a hacky work around. I run a sloppy script to run curator every day at midnight 05, all shards get reallocated and I am good. But I wouldn't think this is necessary seeing that I created a template with the settings therein.

---

<div class="post-metadata">

### Author: ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)
#### Post date: [September 20, 2016, 11:43am UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/9 "2016-09-20T11:43:29Z")

</div>

I think you have to remove first level 'index' within 'settings'. See example [https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html)

---

<div class="post-metadata">

### Author: ![tgdesrochers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tgdesrochers/32/51322_2.png) [@tgdesrochers](https://discuss.elastic.co/u/tgdesrochers)
#### Post date: [September 20, 2016, 11:53am UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/10 "2016-09-20T11:53:13Z")

</div>

I don't quite understand what you mean by "first level index"

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [September 20, 2016, 2:27pm UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/11 "2016-09-20T14:27:55Z")

</div>

> [@tgdesrochers](#):
>
> When I run curator to set the routing allocation I can see a second setting for shards, replicas,

This made me suspicious as well, I think your template that you posted in the first posting has an "index" level too much as @johtani already suggested:

```auto
{
  "order": 2,
  "template": "*",
  "settings": {
    "index": { <-- This can go?? including the closing bracket
      "index": {
        "routing": {
          "allocation": {
            "require": {
              "box_type": "hot"
            }
          }
        }
      },
      "refresh_interval": "5s",
      "number_of_shards": "10",
      "number_of_replicas": "1"
    }
  },
  "mappings": {},
  "aliases": {}
}

```

---

<div class="post-metadata">

### Author: ![tgdesrochers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tgdesrochers/32/51322_2.png) [@tgdesrochers](https://discuss.elastic.co/u/tgdesrochers)
#### Post date: [September 20, 2016, 2:50pm UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/12 "2016-09-20T14:50:36Z")

</div>

ahhhh. Thank you. I will try and when things get recreated tonight I will report back

---

<div class="post-metadata">

### Author: ![tgdesrochers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tgdesrochers/32/51322_2.png) [@tgdesrochers](https://discuss.elastic.co/u/tgdesrochers)
#### Post date: [September 21, 2016, 11:47am UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/13 "2016-09-21T11:47:13Z")

</div>

SOLVED

Just wanted to reply back and say thank you. Apparently my inexperience as an elastic admin showed and I made a simple syntax error that has caused me trouble for weeks.

After removing the second "index" and its brackets my index template works as expected.

Thank you for you help,

---

<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: [July 5, 2017, 10:18pm UTC](https://discuss.elastic.co/t/elastic-template-to-manage-settings/60502/14 "2017-07-05T22:18:33Z")

</div>


