Index template creation: can we parameterize the shards and replica

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": {}
}
}

No. Why do you want to do this?

@dadoonet , Thanks for your replay.

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

Why not specifying this in the index settings then?

1 Like

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.

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?

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.

That's what we call index settings.

I meant:

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.

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