AI Hints
Home›Elasticsearch Tutorial›Templates and Strict Mappings
Elasticsearch · Lesson 49 of 120

Index Templates

Settings for new indexes.

⏱ 2 min read▶ Video at 45:29🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Trailhead stores orders in one index per month. Orders twenty twenty six oh one, oh two, and so on. Every new index needs the same mapping. An index template applies it automatically.

  • One index per month
  • Same mapping
  • Template

A template for orders

The index patterns say, apply to any index whose name starts with orders dash. The template holds the settings and mappings. Then we index an order into a brand new monthly index. Run it. The new index got the template's mapping automatically.

Dev Tools Consoletext
PUT _index_template/orders
{
  "index_patterns": ["orders-*"],
  "template": {
    "settings": { "number_of_replicas": 0 },
    "mappings": { "properties": {
      "order_id": { "type": "keyword" },
      "total":    { "type": "scaled_float", "scaling_factor": 100 } } }
  }
}

POST orders-2026-11/_doc?filter_path=result
{ "order_id": "TH-12001", "total": 89.5 }

GET orders-2026-11/_mapping/field/order_id?filter_path=*.mappings.*.mapping
Output
# PUT _index_template/orders 200 OK
{"acknowledged": true}

# POST orders-2026-11/_doc 201 Created
{"result": "created"}

# GET orders-2026-11/_mapping/field/order_id 200 OK
{
  "orders-2026-11": {
    "mappings": {
      "order_id": {"mapping": {"order_id": {"type": "keyword"}}}
    }
  }
}

Template tips

Templates only apply when an index is created. Existing indexes don't change. Priority decides which template wins, if several patterns match. And component templates let you share pieces, like a common settings block.

keyvalue
Whenat index creation
Existing indexesunchanged
prioritywhich template wins
Componentsreusable pieces

Summary

An index template gives every new matching index the same settings and mappings. Next, stopping surprise fields with strict mappings.

Key takeaways
  • _index_template
  • index_patterns
  • Auto-applied
Next up: Strict Mappings — no surprise fields