If an index name matches multiple index templates, OpenSearch applies the template with the highest priority value. If no priority is specified, it defaults to 0.
For example, if you have a template for books-* with priority: 0 and another for books-fiction-* with priority: 1, an index named books-fiction-romance will use the settings from the books-fiction-* template because its priority is higher.
# Template with default priority
client.indices.put_index_template(
name='books',
body={
'index_patterns': ['books-*'],
'priority': 0,
'template': {
'settings': {
'index': {
'number_of_shards': 3,
'number_of_replicas': 0
}
}
}
}
)
# Template with higher priority
client.indices.put_index_template(
name='books-fiction',
body={
'index_patterns': ['books-fiction-*'],
'priority': 1,
'template': {
'settings': {
'index': {
'number_of_shards': 1,
'number_of_replicas': 1
}
}
}
}
)