Use index templates to auto-apply mappings and settings to all indices matching a pattern.
Index Templates
# Create a template (applied when new index matches pattern)
PUT /_index_template/logs-template
{
"index_patterns": ["logs-*"],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"index.lifecycle.name": "logs-policy"
},
"mappings": {
"properties": {
"timestamp": { "type": "date" },
"level": { "type": "keyword" },
"message": { "type": "text" },
"host": { "type": "keyword" }
}
}
},
"priority": 100
}
# New index matching logs-* gets these settings automatically
PUT /logs-2024-01