liveBook · Manning

Component template

As explained in Elasticsearch in Action, Second Edition

A component template is a reusable Elasticsearch template fragment that can be associated with multiple composable index templates.

A component template is a reusable block of Elasticsearch configuration. It becomes useful when a composable index template attaches it to one or more index patterns, allowing shared settings or mappings to be maintained once and reused across indexes. section 6.6 section 6.6.2

Share development settings and mappings

Create separate components for an environment’s settings and mapping schema, then compose them into a cars template: POST _component_template/dev_settings_component_template { "template": { "settings": { "number_of_shards": 3, "number_of_replicas": 3 } } } POST _component_template/dev_mapping_component_template { "template": { "mappings": { "properties": { "created_by": { "type": "text" }, "version": { "type": "float" } } } } } POST _index_template/composed_cars_template { "index_patterns": ["*cars*"], "priority": 200, "composed_of": [ "dev_settings_component_template", "dev_mapping_component_template" ] } The component requests define reusable configuration but no index pattern. The index template supplies the pattern and combines both components; indexes such as vintage_cars or cars_sold_in_feb then receive the resulting settings and mappings. section 6.6.2

Keep these operational rules in mind:

  • Associate a component template with an index template before relying on it; by itself, it has no index pattern and is not useful for index creation. section 6.6 section 6.6.2
  • Reuse one component across multiple composable index templates, such as sharing development settings among several index families. section 6.6
  • Resolve overlaps carefully: higher-priority matching index templates take precedence, while explicitly supplied index settings take precedence over template configuration. section 6.6 section 6.6.1
Figure 6.6 Composable (index) templates are composed of component templates.

Use the composition diagram to see how several index templates can share component templates while a standalone index template remains independent. section 6.6

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Demonstrates endpoint creation, settings and mappings, composition, index matching, reuse, and precedence rules.
Examples
Uses development shard and replica settings, created_by and version mappings, and a cars index pattern.
What it assumes
Assumes basic index-template and index-creation knowledge while introducing component reuse from configuration examples.
What you can do after
Operate/configure Elasticsearch by creating reusable components and attaching them through composable index templates.
How it connects
Connects component templates to composable index templates, index patterns, mappings, settings, and template priority.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.