# Index Template Not Apllying Correctly

**URL:** https://discuss.elastic.co/t/index-template-not-apllying-correctly/155750
**Category:** Elasticsearch
**Created:** [November 7, 2018, 3:41pm UTC](https://discuss.elastic.co/t/index-template-not-apllying-correctly/155750 "2018-11-07T15:41:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MultiplierMultiplier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/multipliermultiplier/32/25063_2.png) [@MultiplierMultiplier](https://discuss.elastic.co/u/MultiplierMultiplier)
#### Post date: [November 7, 2018, 3:41pm UTC](https://discuss.elastic.co/t/index-template-not-apllying-correctly/155750/1 "2018-11-07T15:41:59Z")

</div>

Hi All,

I have a cluster of ES nodes with 3 nodes in total, I would like two replica shards for each primary, I have implemented the below template which does not appear to work, any advice?

```
{
  "graylog-internal" : {
    "order" : 0,
    "template" : "graylog_*",
    "settings" : {
      "index" : {
        "number_of_shards" : "2",
        "number_of_replicas" : "2"
      }
    },
    "mappings" : {
      "message" : {
        "properties" : {
          "message" : {
            "type" : "text",
            "analyzer" : "standard",
            "fielddata" : false
          },
          "full_message" : {
            "type" : "text",
            "analyzer" : "standard",
            "fielddata" : false
          },
          "timestamp" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "streams" : {
            "type" : "keyword"
          }
        },
        "dynamic_templates" : [
          {
            "internal_fields" : {
              "match" : "gl2_*",
              "mapping" : {
                "type" : "keyword"
              }
            }
          }
        ]
      }
    },
    "aliases" : { }
  }
}

```

The above is returned from curl -XGET 'localhost:9200/\_template?pretty'

Regards,

George

---

<div class="post-metadata">

### Author: ![Ritesh\_Uniyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritesh_uniyal/32/43678_2.png) [@Ritesh\_Uniyal](https://discuss.elastic.co/u/Ritesh_Uniyal)
#### Post date: [November 7, 2018, 4:17pm UTC](https://discuss.elastic.co/t/index-template-not-apllying-correctly/155750/2 "2018-11-07T16:17:07Z")

</div>

your template should be like following. If the index already exists then you will need to rollover the index for template changes to take effect

{  
"graylog-internal": {  
"index\_patterns": [  
“Your pattern”  
],  
"settings": {  
"index": {  
"number\_of\_shards": “2”,  
"number\_of\_replicas": "2",  
"refresh\_interval": "5s"  
}  
},  
"mappings": {},  
"aliases": {}  
}  
}

---

<div class="post-metadata">

### Author: ![victorhearnyeates](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/victorhearnyeates/32/37345_2.png) [@victorhearnyeates](https://discuss.elastic.co/u/victorhearnyeates)
#### Post date: [November 7, 2018, 4:34pm UTC](https://discuss.elastic.co/t/index-template-not-apllying-correctly/155750/3 "2018-11-07T16:34:17Z")

</div>

If you want it to take effect on existing data, you'll need to reindex those indices, which can be done by `reindex` or `update_by_query`. Also be aware that shards and replicas aren't the same thing, shards partition data within an index, while replicas give you a separate copy, which can help with throughput.

i.e.

```auto
    POST _reindex
         {
          "source": {
            "index": "graylog-internal"
           },
           "dest": {
            "index": "new_graylog-internal"
          }
         }

```

or in-situ,

```auto
   POST graylog-internal/_update_by_query

```

As always, make sure you backup/snapshot before doing anything.

Hope this helps 🙂

---

<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: [December 5, 2018, 4:34pm UTC](https://discuss.elastic.co/t/index-template-not-apllying-correctly/155750/4 "2018-12-05T16:34:23Z")

</div>

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