Adding template for index patterns – How to solve related issues

Adding template for index patterns – How to solve related issues

Opster Team

Feb-21, Version: 1.7-8.0

To understand when and why you should add templates for indices, you should rung the Elasticsearch Error Check-Up that can help you improve your Elasticsearch configuration.

This guide will help you check for common problems that cause the log “Adding template for index patterns” to appear. It’s important to understand the issues related to the log, so to get started, read the general overview on common issues and tips related to the Elasticsearch concepts: cluster, index, metadata and template.

What this error means

This log message is an INFO message saying that a template has been created for a given index pattern. Elasticsearch applies templates to new indices based on an index pattern that matches the index name.

Below is an example of an index template, applied only at the index creation time for all the indices matching opster-* and elastic-* pattern.

Adding template for index patterns

What are index templates?

Index templates initialize the indices with predefined mapping and settings. Templates do not affect the existing indexes, but are applied when new indices are created. Whenever we create an index that matches the corresponding template, the template will be applied and the index will have the mappings and settings defined in the template.

How to create an index template

You can create an index template as shown below that will match any indices matching the names opster-* and elastic-*.

PUT/_template/opsterelasticsearch 
{
 "index_patterns": [
   "opster-*",
   "elastic-*"
 ],
 "mappings": {
   "properties": {
     "id": {
       "type": "keyword"
     },
     "location": {
       "type": "geo_point"
     },
     "movie": {
       "type": "text"
     }
   }
 }
}

In response, you will get:

{
 "acknowledged": true
}

When the index template is created, the following log is generated:

adding template [opsterelasticsearch] for index patterns [opster-*, elasticsearch-*]

Now you can create an index that will match the template’s definition and add data to it:

POST/ opster-1/_doc/1
 
{
 "id": 158,
 "location": "1.486912, 2.493157",
 "movie": "Harry Potter"
}

Get a list of all the templates using:

GET  / _cat/templates

Log Context

Log “Adding template [{}] for index patterns {}” classname is MetaDataIndexTemplateService.java
We extracted the following from Elasticsearch source code for those seeking an in-depth context :

                 }
                IndexTemplateMetaData template = templateBuilder.build();

                MetaData.Builder builder = MetaData.builder(currentState.metaData()).put(template);

                logger.info("adding template [{}] for index patterns {}"; request.name; request.indexPatterns);
                return ClusterState.builder(currentState).metaData(builder).build();
            }

            
Override
            public void clusterStateProcessed(String source; ClusterState oldState; ClusterState newState) {



 

Run the Check-Up to get customized recommendations like this:

error

The high disk watermark threshold is about to be reached in specific nodes

error-img

Description

There are various “watermark” thresholds on each Elasticsearch cluster. When the high disk watermark threshold has been exceeded, it means disk space is running out. The node will…

error-img

Recommendations

Based on your specific ES deployment you should…

1

X-PUT curl -H [a customized code snippet to resolve the issue]

Optimize Elasticsearch Performance

Run The Tool