Chapter 09 · Dynamic Templates, Index Templates, Component Templates, and Schema Evolution

Composable Index Templates, Component Templates, Priorities, Simulation, and Environment Promotion

Compose reusable mappings/settings into versioned index templates, resolve overlap deterministically with priorities, simulate representative index names, and promote the same artifact across environments.

Intermediate100–120 minutesSchema evolution labElasticsearch 9.5.3 · OpenSearch 3.8.0Last reviewed: September 2026

Learning outcomes

Hand-created AtlasMart indices drift: one developer changes replica count in test, another pastes a mapping into production, and a third creates an index before the intended template exists. Composable templates turn mappings/settings/aliases into named deployment artifacts, but only if precedence and overlap are deterministic.

01

Separate reusable component templates from the index template that selects concrete index names.

02

Explain merge order, direct-template precedence, explicit create-index overrides, and highest-priority template selection.

03

Use simulate-template and simulate-index APIs as pre-deployment tests rather than discovering precedence after index creation.

04

Promote the same versioned template artifact through environments without hand-edit drift.

05

Detect product/built-in template collisions and preserve evidence of the resolved mapping/settings before creation.

Chapter baseline reviewed 11 September 2026

The reproducible examples target self-managed Elasticsearch 9.5.3 and OpenSearch 3.8.0 using the existing AtlasMart local-course conventions: Elasticsearch on https://localhost:9200 with its copied CA certificate, OpenSearch on https://localhost:9201 with the disposable demo certificate explicitly treated as local-only, and no moving latest tags. Template and mapping syntax is verified against current official documentation. The mandatory REST shape—component templates, composable index templates, priority and simulation—is supported by both products. Built-in templates and managed-service defaults can add environment-specific overlap, so simulation must run against the target cluster rather than only in a local JSON linter.

Execution and safety note

The generation environment does not run the two search servers, so commands are specified as deterministic labs and expected invariants rather than represented as captured live output. Run them only against the disposable AtlasMart course indices/templates, record the actual API responses from your pinned versions, and never test alias cutover or destructive cleanup against production names.

1. Separate reusable components from selection policy

Dev Tools · AtlasMart v1 components and index template
PUT _component_template/atlasmart-products-mappings-v1
{
  "version": 1,
  "_meta": {"owner":"search-platform", "schema":"atlasmart-products", "generation":1},
  "template": {
    "mappings": {
      "dynamic": "strict",
      "properties": {
        "product_id": {"type":"keyword"},
        "name": {"type":"text", "fields":{"keyword":{"type":"keyword","ignore_above":256}}},
        "category": {"type":"keyword"},
        "price": {"type":"scaled_float", "scaling_factor":100},
        "available": {"type":"boolean"},
        "updated_at": {"type":"date"}
      }
    }
  }
}

PUT _component_template/atlasmart-products-settings-v1
{
  "version": 1,
  "_meta": {"owner":"search-platform", "schema":"atlasmart-products", "generation":1},
  "template": {
    "settings": {"number_of_shards":1, "number_of_replicas":0}
  }
}

PUT _index_template/atlasmart-products-template-v1
{
  "index_patterns":["atlasmart-products-v1-*"] ,
  "priority": 200,
  "version": 1,
  "_meta": {"owner":"search-platform", "schema":"atlasmart-products", "generation":1},
  "composed_of":["atlasmart-products-settings-v1","atlasmart-products-mappings-v1"]
}
Artifact Responsibility When applied
component template: mappings Reusable field/search contract Only when referenced by a matching index template at index creation.
component template: settings Reusable shard/replica/settings contract At creation; changing the component later does not rewrite existing indices.
index template Index-pattern selection, priority, component composition, direct overrides When a new index/data stream matches.
create-index request Concrete index creation and explicit overrides Highest precedence for values explicitly supplied in the request.

2. Precedence is part of the schema

For the portable core used here, later components in composed_of can override earlier component values; mappings/settings directly in the index template are applied after components; and explicit create-index settings/mappings take precedence for the fields/options supplied there. When multiple composable index templates match, the highest priority wins. That means priority numbers and component order must be code-reviewed just like mappings.

Dev Tools · overlap plus concrete-name simulation
PUT _index_template/atlasmart-products-template-catchall
{
  "index_patterns":["atlasmart-products-*"] ,
  "priority": 50,
  "template":{"settings":{"number_of_replicas":0}}
}

PUT _index_template/atlasmart-products-template-v1
{
  "index_patterns":["atlasmart-products-v1-*"] ,
  "priority": 200,
  "version": 1,
  "_meta":{"owner":"search-platform","schema":"atlasmart-products","generation":1},
  "composed_of":["atlasmart-products-settings-v1","atlasmart-products-mappings-v1"]
}

POST _index_template/_simulate_index/atlasmart-products-v1-000001

Inspect the simulation result for final settings, mappings, aliases, and overlap metadata where exposed. The evidence question is not “does my template exist?” but “what would atlasmart-products-v1-000001 actually receive right now?”

3. Simulate a candidate before installing it

Dev Tools · dry-run a candidate template body
POST _index_template/_simulate
{
  "index_patterns":["atlasmart-products-v2-*"] ,
  "priority": 210,
  "version": 2,
  "composed_of":["atlasmart-products-settings-v1","atlasmart-products-mappings-v1"],
  "template": {
    "mappings": {
      "properties": {
        "brand":{"type":"keyword"}
      }
    }
  }
}

This dry run is a deployment gate. Assert not only that it returns HTTP 200, but that the resolved contract contains the intended fields/settings and no unexpected higher-priority overlap. In Elastic environments, also avoid collisions with built-in index-template patterns/priority bands. Managed platforms may inject or constrain templates differently; inspect the actual target.

4. A valid template can still be an operationally wrong template

Wrong approach · priority accident
Template A: pattern atlasmart-products-*    priority 100
Template B: pattern atlasmart-products-v2-* priority 50

Index: atlasmart-products-v2-000001

Assumption: "B is more specific, so B wins."
Reality: composable template resolution uses priority; the higher-priority matching template wins.
Repair: choose/document non-overlapping patterns or explicit priority policy, then simulate the concrete name.

Do not rely on visual “specificity” of wildcard patterns. The priority value is executable behavior. Likewise, do not use environment-specific hand edits to fix a template after promotion; that creates drift invisible to source control.

5. Environment promotion: same artifact, environment inputs outside schema

Promotion manifest
schema_artifact: atlasmart-products
schema_generation: 1
component_templates:
  - atlasmart-products-settings-v1
  - atlasmart-products-mappings-v1
index_template: atlasmart-products-template-v1
expected_pattern: atlasmart-products-v1-*
expected_priority: 200
server_matrix:
  elasticsearch: 9.5.3
  opensearch: 3.8.0
preflight:
  - template/component inventory captured
  - simulate candidate template
  - simulate concrete index name
  - assert mapping/settings/aliases
  - assert no unexpected overlap
  - create disposable canary index
  - delete canary after evidence capture

Credentials, CA paths and managed endpoint names are deployment configuration, not reasons to fork the schema JSON. Product-specific capabilities may require separate artifacts, but “prod was edited manually” is never an acceptable schema branch.

6. Component updates are not retroactive

Updating atlasmart-products-mappings-v1 changes what future matching indices receive; existing indices keep the mapping/settings they were created with unless a supported mapping/settings update is explicitly applied. This is why mutating a component under the same version name is risky: the same apparent generation can produce different physical indices over time. Prefer immutable/versioned component names for material changes.

Check your understanding

  1. What selects between two matching composable index templates?
  2. Do component-template changes rewrite existing indices?
  3. Why simulate a concrete index name?
  4. Why is hand-editing production templates dangerous?
  5. What should be versioned besides mappings?
Review the answers

1. Priority; the highest-priority matching index template wins.

2. No. Components are resolved during creation; existing indices retain their current configuration unless separately updated.

3. It tests actual pattern/priority resolution and reveals the final settings/mappings/aliases that name would receive.

4. It creates configuration drift not represented by the promoted artifact or its tests.

5. Component order, settings, index-pattern/priority, aliases, metadata and the compatibility matrix.

Production judgment

Template deployment is cluster-state deployment. Limit who can manage templates, review overlap and priority policy, monitor template changes, and keep promotion auditable. A template simulation does not benchmark indexing/search performance; run separate canary/load tests for shard/analysis/storage effects. Backup and restore plans must preserve both data and the schema artifacts required to create future indices consistently.

Summary and next step

AtlasMart now has versioned reusable template artifacts and deterministic resolution tests. The next lesson handles the harder case: a field contract that cannot be changed in place, requiring a new index generation, controlled reindex, validation, alias cutover and rollback.

Authoritative references

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only Ethereum or ERC-20 compatible assets to this address.