# How to import template for ES 7.12.0?

**URL:** <https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041>\
**Category:** APM\
**Tags:** docker, server\
**Created:** [August 20, 2021, 7:14am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041 "2021-08-20T07:14:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 20, 2021, 7:14am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/1 "2021-08-20T07:14:07Z")

</div>

I am using ES 7.12.0 and APM 7.8.1. Today, I want to upgrade APM to 7.14.0, but APM cannot automatically create a template, so I want to import it manually and encounter some problems.

```auto
./apm-server setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["192.168.10.140:9200"]' -E 'output.elasticsearch.username: elastic' -E 'output.elasticsearch.password: elastic'
Exiting: couldn't connect to any of the configured Elasticsearch hosts. Errors: [error connecting to Elasticsearch at http://192.168.10.140:9200: 401 Unauthorized: {"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401}]

```

First, I execute the following command, but return to http401. I need to enter the account and password. There is no mark on how to write the account and password in the document.  
`docker run docker.elastic.co/apm/apm-server:7.14.0 setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["192.168.10.140:9200"]'`

Then I use curl to import JSON. The ES server never returns results. After a period of time, it returns "curl: (52) empty reply from server"

`curl -XPUT -u elastic:elastic -H 'Content-Type: application/json' http://192.168.10.140:9200/_template/apm-server-7.14.0 -d@apm-server.template.json`

Finally, I used binary import without success.

```auto
./apm-server setup --index-management -E output.logstash.enabled=false -c apm.yaml
Exiting: error loading template apm-7.14.0-error: failed to load template: couldn't load template: Put "http://192.168.10.140:9200/_template/apm-7.14.0-error": EOF. Response body:

```

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 21, 2021, 7:39am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/2 "2021-08-21T07:39:13Z")

</div>

I found that the path of the template has changed. I modified the path but it still doesn’t work.

`curl -XPUT -u elastic:elastic -H 'Content-Type: application/json' http://192.168.10.140:9200/_index_template/apm-server-7.14.0 -d@apm-server.template.json `  
`curl: (52) Empty reply from server`

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 23, 2021, 2:32am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/3 "2021-08-23T02:32:48Z")

</div>

I modified the template format, but there are still errors.  
[https://paste.ubuntu.com/p/Zv4w5dkw23/](https://paste.ubuntu.com/p/Zv4w5dkw23/)

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "composable template [simulate_template_uoxlrnqxr_c8eelk9nsykq] template after composition is invalid"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "composable template [simulate_template_uoxlrnqxr_c8eelk9nsykq] template after composition is invalid",
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "invalid composite mappings for [simulate_template_uoxlrnqxr_c8eelk9nsykq]",
      "caused_by" : {
        "type" : "mapper_parsing_exception",
        "reason" : "Failed to parse mapping [_doc]: template must have match, path_match or match_mapping_type set {mapping={type=histogram}}",
        "caused_by" : {
          "type" : "mapper_parsing_exception",
          "reason" : "template must have match, path_match or match_mapping_type set {mapping={type=histogram}}"
        }
      }
    }
  },
  "status" : 400
}

```

---

<div class="post-metadata">

**Author:** ![Martijn\_Laarman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman/32/4410_2.png) [@Martijn\_Laarman](https://discuss.elastic.co/u/Martijn_Laarman)\
**Post date:** [August 23, 2021, 9:46am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/4 "2021-08-23T09:46:25Z")

</div>

Hi @wajika,

APM still uses legacy index templates so to update the template it would have to use the following API:

`http://192.168.10.140:9200/_template/apm-server-7.14.0` whereas your example points to the new Index Templates v2 API from Elasticsearch. Our documentation around export/import templates also still uses the legacy v1 API's:

> **[Load the Elasticsearch index template | APM Server Reference \[7.14\] | Elastic](https://www.elastic.co/guide/en/apm/server/current/apm-server-template.html#load-template-manually-alternate)**

When you initially went through the CLI setup the format to specify the Elasticsearch username and password was slightly off:

`-E 'output.elasticsearch.username: USERNAME'` where it should be: `-E 'output.elasticsearch.username=USERNAME'`

Causing the unauthorized message.

If you want to bootstrap everything through the CLI again you can use the following:

`./apm-server setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["https://ELASTICSEARCH_DEPLOYMENT"]' -E 'output.elasticsearch.username=USERNAME' -E 'output.elasticsearch.password=PASSWORD' -E 'setup.template.overwrite=true' -E 'apm-server.ilm.setup.overwrite=true' -e -d "*"`

Be aware that templates only apply to newly created indices and won't apply retroactively so you might have to rollover your indices manually.

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 24, 2021, 12:58am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/5 "2021-08-24T00:58:09Z")

</div>

Thank you for the method, I succeeded.

```auto
> ./apm-server setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["https://ELASTICSEARCH_DEPLOYMENT"]' -E 'output.elasticsearch.username=USERNAME' -E 'output.elasticsearch.password=PASSWORD' -E 'setup.template.overwrite=true' -E 'apm-server.ilm.setup.overwrite=true' -e -d "*"

```

For the api v1 version you mentioned, I tried it, but it didn't work. It can be reproduced, and finally it prompts "[index\_template] unknown field [mappings]".

1、./apm-server export template \> apm-server.template.json  
2、copy the content to kibana dev tools

 ![kibana](https://us1.discourse-cdn.com/elastic/original/3X/6/f/6f3a0035e880f976b706ee99c8c2118e26d5c359.png)

Later I changed the format to api v2, and the prompt of kibana changed. Although it is still unsuccessful

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/6/b625c41af12ef6547289e6dc4b798a81af51dc5c.png)

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 24, 2021, 1:35am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/6 "2021-08-24T01:35:41Z")

</div>

```auto
{"log.level":"error","@timestamp":"2021-08-24T01:19:29.057Z","log.logger":"publisher_pipeline_output","log.origin":{"file.name":"pipeline/output.go","file.line":154},"message":"Failed to connect to backoff(elasticsearch(http://192.168.10.141:9200)): Connection marked as failed because the onConnect callback failed: error loading Elasticsearch template: failed to load template: couldn't load template: 400 Bad Request: {\"error\":{\"root_cause\":[{\"type\":\"mapper_parsing_exception\",\"reason\":\"No type specified for field [headers]\"}],\"type\":\"mapper_parsing_exception\",\"reason\":\"Failed to parse mapping [_doc]: No type specified for field [headers]\",\"caused_by\":{\"type\":\"mapper_parsing_exception\",\"reason\":\"No type specified for field [headers]\"}},\"status\":400}. Response body: {\"error\":{\"root_cause\":[{\"type\":\"mapper_parsing_exception\",\"reason\":\"No type specified for field [headers]\"}],\"type\":\"mapper_parsing_exception\",\"reason\":\"Failed to parse mapping [_doc]: No type specified for field [headers]\",\"caused_by\":{\"type\":\"mapper_parsing_exception\",\"reason\":\"No type specified for field [headers]\"}},\"status\":400}","service.name":"apm-server","event.dataset":"apm-server","ecs.version":"1.6.0"}

```

@Martijn_Laarman I tried to upgrade the apm server to 7.14.0, but it didn’t work

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 25, 2021, 2:00am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/7 "2021-08-25T02:00:13Z")

</div>

```auto
{
	"error": {
		"root_cause": [{
			"type": "mapper_parsing_exception",
			"reason": "No type specified for field [headers]"
		}],
		"type": "mapper_parsing_exception",
		"reason": "Failed to parse mapping [_doc]: No type specified for field [headers]",
		"caused_by": {
			"type": "mapper_parsing_exception",
			"reason": "No type specified for field [headers]"
		}
	},
	"status": 400
}

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/c/7ca7ff423418a90ef9af10d38547d5e862094177.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/4/74d2bdd8d4979ff8ccff5442d451a3c4752d0ac4.png)

Whether it is manually executing the dsl statement or importing the template in other ways, the error always prompts "Failed to parse mapping [\_doc]: No type specified for field [headers]". I checked that the dsl contains type: object. Why? Still showing error?

---

<div class="post-metadata">

**Author:** ![Martijn\_Laarman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman/32/4410_2.png) [@Martijn\_Laarman](https://discuss.elastic.co/u/Martijn_Laarman)\
**Post date:** [August 25, 2021, 11:44am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/8 "2021-08-25T11:44:09Z")

</div>

In your example in the developer session you still called `/_index_template` and not `/_template`

You might have competing templates now and in fact `v2 templates under /_index_template` will take precedence.

What does `GET /_cat/templates/*apm*?v&h=*` return?

You might have to remove some/all templates and rely only on the CLI command to recreate all templates.

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 26, 2021, 12:30am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/9 "2021-08-26T00:30:49Z")

</div>

`/_index_template` and `/_template` I have used it, the result of importing the template is true, but after the apm server runs, it will prompt an error.

apm server full log  
[https://paste.ubuntu.com/p/FcYMVH7ZhJ/](https://paste.ubuntu.com/p/FcYMVH7ZhJ/)

```auto
Error message：
Failed to parse mapping [_doc]: No type specified for field [headers]

```

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [August 26, 2021, 2:05am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/10 "2021-08-26T02:05:50Z")

</div>

I don't know why you're getting that error.

I see this message in the log:

> {"log.level":"info","@timestamp":"2021-08-25T01:48:01.445Z","log.origin":{"file.name":"template/load.go","file.line":229},"message":"Existing template will be overwritten, as overwrite is enabled.","service.name":"apm-server","event.dataset":"apm-server","ecs.version":"1.6.0"}

Do you have `setup.template.overwrite: true` set in your `apm-server.yml`?

If you have setup the template manually, then you should configure APM Server to not overwrite the template, and you should then no longer see these errors.

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 27, 2021, 5:56am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/11 "2021-08-27T05:56:01Z")

</div>

> [@wajika](#):
>
> `./apm-server setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["https://ELASTICSEARCH_DEPLOYMENT"]' -E 'output.elasticsearch.username=USERNAME' -E 'output.elasticsearch.password=PASSWORD' -E 'setup.template.overwrite=true' -E 'apm-server.ilm.setup.overwrite=true' -e -d "*"`

The command i used:  
`./apm-server setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["https://ELASTICSEARCH_DEPLOYMENT"]' -E 'output.elasticsearch.username=USERNAME' -E 'output.elasticsearch.password=PASSWORD' -E 'setup.template.overwrite=true' -E 'apm-server.ilm.setup.overwrite=true' -e -d "*"`

I modified setup.template.overwrite=false and it worked.  
I think it should be the wrong order of my operations that caused this problem.

Thank you for your analysis @axw

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 27, 2021, 5:57am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/12 "2021-08-27T05:57:52Z")

</div>

In this case, if they are not professional personnel, how do they troubleshoot?

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [August 29, 2021, 5:48am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/13 "2021-08-29T05:48:54Z")

</div>

> In this case, if they are not professional personnel, how do they troubleshoot?

The current approach to managing templates, ingest pipelines, etc. is not ideal, and can be difficult to troubleshoot as you have found. We have been working on something that should help here: [Switch to the Elastic APM integration | APM User Guide [8.11] | Elastic](https://www.elastic.co/guide/en/apm/server/current/apm-integration.html)

With the new APM integration for Elastic Agent, installation of index templates and pipelines will done by Fleet, managed through Kibana. We expect this to be much more user friendly, and less error prone.

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [August 30, 2021, 1:01am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/14 "2021-08-30T01:01:14Z")

</div>

Thank you for your reply.  
I will try fleet if I have time.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 27, 2021, 1:01am UTC](https://discuss.elastic.co/t/how-to-import-template-for-es-7-12-0/282041/15 "2021-09-27T01:01:57Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
