Master Elasticsearch Index Templates, Aliases, and Node Types in ES 7.8
This guide explains how to define and use Elasticsearch index templates, manage index aliases, configure the _source field, and understand the roles of master, data, and coordinating nodes in a 7.8 cluster, with practical API examples and visual illustrations.
Environment: Elasticsearch 7.8.0
Index Templates
By defining a template in advance, Elasticsearch automatically applies the template's configuration when an index is created whose name matches the template's index pattern. If multiple templates match, the one with the highest
ordervalue takes precedence.
<code>{
"order": 0, // template priority
"index_patterns": "xxx_yyy_*", // supports wildcards
"settings": {...},
"mappings": {...},
"aliases": {...}
}</code>Creating a Template
PUT http://localhost:9200/_template/t-order-tpl
<code>{
"index_patterns": ["t-order-*"],
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"_source": {"enabled": true},
"properties": {
"sno": {"type": "keyword"},
"name": {"type": "text", "analyzer": "ik_max_word"},
"price": {"type": "double"},
"created": {"type": "date"}
}
}
}</code>Viewing Templates
GET http://localhost:9200/_cat/templates?v
The default
orderis 0.
Index Aliases
Index aliases allow seamless switching between different index versions, similar to database views. Operations use the alias, while Elasticsearch internally maps it to the actual index.
Creating an Alias
Method 1: Define the alias in the index template so it is applied automatically when the index is created.
Method 2: Use the alias APIs.
POST http://localhost:9200/t-order-20210513/_alias/order-01
POST http://localhost:9200/_aliases
<code>{
"actions" : [
{ "add" : { "index" : "t-order-20210513", "alias" : "order-02" } }
]
}</code>Batch operations:
POST http://localhost:9200/_aliases
<code>{
"actions" : [
{ "add" : { "index" : "t-order-20210513", "alias" : "order-03" } },
{ "add" : { "index" : "t-order-20210513", "alias" : "order-04" } }
]
}</code>Viewing indices after alias operations can be done with the standard cat APIs.
_source Field
The
_sourcefield is enabled by default, storing the original JSON document. Disabling it can save disk space when only the document ID is needed for lookups.
Default behavior stores both the original document and an inverted index.
<code>"mappings": {
"_source": { "enabled": false },
"properties": {
"name": { "type": "text" }
}
}</code>When disabled, queries no longer return the
_sourcecontent.
Node Types
Master Node
<code># Can be elected as master (true means eligible)
node.master: true</code>Roles: index creation/deletion, cluster membership tracking, shard allocation decisions. In production, it is advisable to separate master nodes from data nodes to improve stability.
Data Node
<code># Data node flag
node.master: false
node.data: true</code>Roles: store index data and handle CRUD and aggregation operations. Requires higher disk and memory resources.
Coordinating Node
<code># Coordinating node (all false)
node.master: false
node.data: false
node.ingest: false</code>Acts as the entry point for client requests, distributes them to data nodes, and merges the results. It should have sufficient CPU and memory for the reduce phase.
In summary, Elasticsearch clusters typically consist of master‑eligible nodes, data nodes, and coordinating nodes, each with distinct resource requirements.
For more details, refer to the official Elasticsearch documentation.
Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.