DBAtlas · Database operations atlas

Build an index template from component templates and simulate the result

ElasticsearchIndex Lifecycle

Command

PUT _component_template/app-mappings
{
  "template": {
    "mappings": {
      "dynamic": "strict",
      "properties": {
        "@timestamp": { "type": "date" },
        "level": { "type": "keyword" },
        "msg": { "type": "text" }
      }
    }
  }
}
PUT _index_template/app-events
{
  "index_patterns": ["app-events-*"],
  "priority": 500,
  "composed_of": ["app-mappings"],
  "template": { "settings": { "number_of_shards": 1, "refresh_interval": "5s" } }
}
# See the final settings and mapping before the index is created:
POST _index_template/_simulate_index/app-events-000001
GET _cat/templates?v&s=name

What it does

Defines a reusable mapping component template, composes it into an index template, and shows the final settings and mapping that would apply to a given index name without creating the index.

When to use it

When new indices are created with the wrong mapping or shard count (dynamic mapping explosion, text instead of keyword), and before rolling out a template change.

Caution

A template applies only to newly created indices; the mapping of existing indices does not change (see reindex-alias-swap). If two templates match the same pattern, only the one with the highest priority is used; they are not merged. dynamic: strict rejects documents containing undefined fields; if the application sends a new field, indexing fails.

Open in DBAtlas →

Related