Adding template for index patterns – How to solve related issues

Opster Team

Feb-21, Version: 1.7-8.0

In addition to reading this guide, we recommend you run the Elasticsearch Template Optimizer to fix problems in your data modeling.

It will analyze your templates to detect issues and improve search performance, reduce indexing bottlenecks and optimize storage utilization. The Template Optimizer is free and requires no installation.

This guide will help you check for common problems that cause the log 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 below. Advanced users might want to skip right to the common problems section in each concept or run the template optimizer.

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) {



 

Watch product tour

Try AutoOps to find & fix Elasticsearch problems

Analyze Your Cluster
Skip to content