# Unable to PUT \_index\_template which was captured from GET \_index\_template

**URL:** <https://discuss.elastic.co/t/unable-to-put-index-template-which-was-captured-from-get-index-template/328221>\
**Category:** Elasticsearch\
**Created:** [March 22, 2023, 8:54am UTC](https://discuss.elastic.co/t/unable-to-put-index-template-which-was-captured-from-get-index-template/328221 "2023-03-22T08:54:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eeijlar](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@eeijlar](https://discuss.elastic.co/u/eeijlar)\
**Post date:** [March 22, 2023, 8:54am UTC](https://discuss.elastic.co/t/unable-to-put-index-template-which-was-captured-from-get-index-template/328221/1 "2023-03-22T08:54:01Z")

</div>

I am getting an index template as follows:

```auto
curl -X GET http://localhost:9200/_index_template/filebeat* > /var/tmp/filebeat-template.json

```

Now I want to PUT the same template into another elastic instance:

```auto
 curl http://localhost:9200/_index_template/filebeat -H 'Content-Type: application/json' -d @/var/tmp/filebeat-template-formatted.json

```

However, it includes several fields which the API won't accept:

```auto
  "index_templates": [
    {
      "name": filebeat-7.17.7",

```

I would like to do this as part of an automated process. Is there any solution other than parsing out the fields?

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [March 22, 2023, 1:35pm UTC](https://discuss.elastic.co/t/unable-to-put-index-template-which-was-captured-from-get-index-template/328221/2 "2023-03-22T13:35:34Z")

</div>

> [@eeijlar](#):
>
> However, it includes several fields which the API won't accept

Please share the full error you are receiving.

---

<div class="post-metadata">

**Author:** ![eeijlar](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@eeijlar](https://discuss.elastic.co/u/eeijlar)\
**Post date:** [March 22, 2023, 4:20pm UTC](https://discuss.elastic.co/t/unable-to-put-index-template-which-was-captured-from-get-index-template/328221/3 "2023-03-22T16:20:15Z")

</div>

I get the following:

```auto
{"error":{"root_cause":[{"type":"x_content_parse_exception","reason":"[1:2] [index_template] unknown field [index_templates] did you mean any of [index_patterns, template]?"}],"type":"x_content_parse_exception","reason":"[1:2] [index_template] unknown field [index_templates] did you mean any of [index_patterns, template]?"},"status":400}[

```

I got it working by parsing out the fields with jq:

```auto
cat metricbeat.json |jq -r '.index_templates[]' | jq -r '.index_template' > metricbeat-fixed.json

```

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [March 22, 2023, 5:00pm UTC](https://discuss.elastic.co/t/unable-to-put-index-template-which-was-captured-from-get-index-template/328221/4 "2023-03-22T17:00:07Z")

</div>

> [@eeijlar](#):
>
> `cat metricbeat.json |jq -r '.index_templates[]' | jq -r '.index_template' > metricbeat-fixed.json`

Yeah, the return of the `GET _index_template` will be an array in the `index_templates` field, this will return every template that matchs your get request, each item in the array will be an index template, so you need to parse as you did.

---

<div class="post-metadata">

**Author:** ![eeijlar](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@eeijlar](https://discuss.elastic.co/u/eeijlar)\
**Post date:** [March 22, 2023, 7:14pm UTC](https://discuss.elastic.co/t/unable-to-put-index-template-which-was-captured-from-get-index-template/328221/5 "2023-03-22T19:14:32Z")

</div>

The solution is to strip out the fields as follows (using jq utility):

```auto
cat metricbeat.json |jq -r '.index_templates[]' | jq -r '.index_template' > metricbeat-fixed.json

```

The curl command then works as expected.

---

<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:** [April 19, 2023, 7:15pm UTC](https://discuss.elastic.co/t/unable-to-put-index-template-which-was-captured-from-get-index-template/328221/6 "2023-04-19T19:15:27Z")

</div>

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