# Index template creation: can we parameterize the shards and replica

**URL:** <https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811>\
**Category:** Elasticsearch\
**Created:** [March 30, 2021, 3:13pm UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811 "2021-03-30T15:13:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![raja\_augstin](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@raja\_augstin](https://discuss.elastic.co/u/raja_augstin)\
**Post date:** [March 30, 2021, 3:13pm UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/1 "2021-03-30T15:13:11Z")

</div>

can't we parameterize index shards and replicas in index template.  
{  
"index\_template\_1": {  
"index\_patterns": [  
"\*"  
],  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"index\_edgeNGram\_analyzer": {  
"filter": [  
"lowercase"  
],  
"tokenizer": "nGram\_tokenizer"  
}  
},  
"tokenizer": {  
"nGram\_tokenizer": {  
"token\_chars": [  
"letter",  
"digit",  
"symbol",  
"punctuation"  
],  
"min\_gram": "1",  
"type": "edgeNGram",  
"max\_gram": "20"  
}  
}  
},  
"number\_of\_shards": "{{val1}}",  
"number\_of\_replicas": "{{val2}}"  
}  
},  
"mappings": {},  
"aliases": {}  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 30, 2021, 3:24pm UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/2 "2021-03-30T15:24:57Z")

</div>

No. Why do you want to do this?

---

<div class="post-metadata">

**Author:** ![raja\_augstin](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@raja\_augstin](https://discuss.elastic.co/u/raja_augstin)\
**Post date:** [March 30, 2021, 3:29pm UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/3 "2021-03-30T15:29:07Z")

</div>

@dadoonet , Thanks for your replay.

i want to customize the different index with its own shards #, bcoz each index varies on size.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 30, 2021, 3:40pm UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/4 "2021-03-30T15:40:08Z")

</div>

Why not specifying this in the index settings then?

---

<div class="post-metadata">

**Author:** ![raja\_augstin](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@raja\_augstin](https://discuss.elastic.co/u/raja_augstin)\
**Post date:** [March 31, 2021, 5:12am UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/5 "2021-03-31T05:12:56Z")

</div>

if i specify in index settings. then it will be same for all the index that i'm going to create using this template, i don't want this to be a static value.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 31, 2021, 6:26am UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/6 "2021-03-31T06:26:15Z")

</div>

I'd see that in the opposite way.

If you set this in a template then that will be applied to all indices which are going to be created later on.

Sorry but how do you imagine this template based solution would work then?  
When will you pass parameters to the template?

---

<div class="post-metadata">

**Author:** ![raja\_augstin](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@raja\_augstin](https://discuss.elastic.co/u/raja_augstin)\
**Post date:** [March 31, 2021, 6:49am UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/7 "2021-03-31T06:49:00Z")

</div>

Reason i chosen the template is to avoid creating same kind of custom analyzers for different types of index, but unfortunately i don't want use the shares and replica are same for all the index that I'm going to create.

in search Template, there is option to parameter the input values for the search query.

so I'm looking similar options is available in index template too.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 31, 2021, 7:08am UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/8 "2021-03-31T07:08:05Z")

</div>

That's what we call index settings.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 31, 2021, 7:36am UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/9 "2021-03-31T07:36:04Z")

</div>

I meant:

```auto
PUT _index_template/template_test
{
  "index_patterns": ["test*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    },
    "mappings": {
      "properties": {
        "foo": {
          "type": "text"
        }
      }
    }
  }
}
PUT test_1
{
    "settings": {
      "number_of_shards": 5,
      "number_of_replicas": 0
    }
}

```

As you can see, you can pass the "parameters" of number of shards and replicas at index creation time.  
If you don't define the shards, a default value will be applied (the ones in the template).

I think that's what you are asking about.

---

<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:** [April 28, 2021, 7:37am UTC](https://discuss.elastic.co/t/index-template-creation-can-we-parameterize-the-shards-and-replica/268811/10 "2021-04-28T07:37:04Z")

</div>

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