I ran into this same issue when transitioning from Elasticsearch 6 to OpenSearch. In Elasticsearch I was accustomed to index templates being additive. For example, in Elasticsearch 6, I could do something like this:
Create an index template to configure ILM rollover alias
PUT _template/a_descriptive_template_name-ilm
{
"settings": {
"index.lifecycle.name": "an_efficient_ilm_policy",
"index.lifecycle.rollover_alias": "a_descriptive_index_name-ilm"
},
"order": 10,
"index_patterns": [
"a_descriptive_index_name-ilm-*"
]
}
Create an index template to configure index shard settings
PUT _template/a_common_template_name
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
},
"order": 5,
"index_patterns": [
"a_descriptive_index_name-ilm-*"
]
}
Create the initial index
PUT a_descriptive_index_name-ilm-000001
{
"aliases": {
"a_descriptive_index_name-ilm": {
"is_write_index": true
}
}
}
Verify the settings
GET a_descriptive_index_name-ilm-000001
{
"a_descriptive_index_name-ilm-000001" : {
"aliases" : {
"a_descriptive_index_name-ilm" : {
"is_write_index" : true
}
},
"mappings" : { },
"settings" : {
"index" : {
"lifecycle" : {
"name" : "an_efficient_ilm_policy",
"rollover_alias" : "a_descriptive_index_name-ilm"
},
"number_of_shards" : "2",
"provided_name" : "a_descriptive_index_name-ilm-000001",
"creation_date" : "1692853100041",
"number_of_replicas" : "1",
"uuid" : "AJ3OiRaXRj2cVCvuKlUWgg",
"version" : {
"created" : "6081299"
}
}
}
}
}
When I tried to do this same technique in Opensearch 2.3, I noticed that it did not work as I expected. The template with the higher priority overwrote the settings in the lower priority template, completely, even if there were not overlapping settings. In the example below, where I am doing the same thing as Elasticsearch (but using different verbs for OpenSearch), you will see that the additive behavior is no longer supported:
Create an index template to configure ISM rollover alias
PUT _index_template/a_descriptive_template_name-ism
{
"template": {
"settings": {
"plugins.index_state_management.rollover_alias": "a_descriptive_index_name-ism"
}
},
"priority": 10,
"index_patterns": [
"a_descriptive_index_name-ism-*"
]
}
Create an index template to configure index shard settings
PUT _index_template/a_common_template_name
{
"template": {
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
}
},
"priority": 5,
"index_patterns": [
"a_descriptive_index_name-ism-*"
]
}
Create the initial index
PUT a_descriptive_index_name-ism-000001
{
"aliases": {
"a_descriptive_index_name-ism": {
"is_write_index": true
}
}
}
Verify the settings
{
"a_descriptive_index_name-ism-000001" : {
"aliases" : {
"a_descriptive_index_name-ism" : {
"is_write_index" : true
}
},
"mappings" : { },
"settings" : {
"index" : {
"number_of_shards" : "1",
"plugins" : {
"index_state_management" : {
"rollover_alias" : "a_descriptive_index_name-ism"
}
},
"provided_name" : "a_descriptive_index_name-ism-000001",
"creation_date" : "1692853523944",
"number_of_replicas" : "1",
"uuid" : "ZZSjabAVQACC7m8Xn0uKtA",
"version" : {
"created" : "136247827"
}
}
}
}
}
As you can see, the "number_of_shards": 2
setting gets overwritten.
To apply both the shard settings and the ISM rollover settings, (and whatever other settings / mappings required), there are two options.
- Combine all the settings / mappings and ISM configuration into a single index template (or single index template per index pattern)
- [Better Solution] Use the OpenSearch Composable index templates functionality to allow for "layering" templates.
The OP answered in a later comment "It does, I have another index template". To solve for this scenario, option 2 is the way I suggest to follow.
Here is an example:
Create a component template to configure index shard settings
PUT _component_template/shards_component_template
{
"template": {
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
}
}
}
Create the index template to configure ILM rollover alias, referencing the component template
PUT _index_template/a_descriptive_template_name-ism
{
"template": {
"settings": {
"plugins.index_state_management.rollover_alias": "a_descriptive_index_name-ism"
}
},
"priority": 10,
"index_patterns": [
"a_descriptive_index_name-ism-*"
],
"composed_of": [
"shards_component_template"
]
}
Create the initial index
PUT a_descriptive_index_name-ism-000001
{
"aliases": {
"a_descriptive_index_name-ism": {
"is_write_index": true
}
}
}
Verify the settings
{
"a_descriptive_index_name-ism-000001" : {
"aliases" : {
"a_descriptive_index_name-ism" : {
"is_write_index" : true
}
},
"mappings" : { },
"settings" : {
"index" : {
"number_of_shards" : "2",
"plugins" : {
"index_state_management" : {
"rollover_alias" : "a_descriptive_index_name-ism"
}
},
"provided_name" : "a_descriptive_index_name-ism-000001",
"creation_date" : "1692854275856",
"number_of_replicas" : "1",
"uuid" : "SGvVILFsSG-3PdpoCg8Tkw",
"version" : {
"created" : "136247827"
}
}
}
}
}