# Open source Elasticsearch does not use template in index creation

**URL:** https://discuss.elastic.co/t/open-source-elasticsearch-does-not-use-template-in-index-creation/245673
**Category:** Elasticsearch
**Created:** [August 19, 2020, 8:25pm UTC](https://discuss.elastic.co/t/open-source-elasticsearch-does-not-use-template-in-index-creation/245673 "2020-08-19T20:25:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hweber](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@hweber](https://discuss.elastic.co/u/hweber)
#### Post date: [August 19, 2020, 8:25pm UTC](https://discuss.elastic.co/t/open-source-elasticsearch-does-not-use-template-in-index-creation/245673/1 "2020-08-19T20:25:53Z")

</div>

I am using an open source build of Elasticsearch, version 7.8.0.  
I executed

```auto
curl -ivvk -H "Content-Type: application/json" -H "Accept: application/json" -u username:password -X PUT "https://localhost:9200/_template/test_template" -d '
{
  "index_patterns": ["test-*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "index.refresh_interval": "5s"
    },
    "mappings": {
      "properties": {
        "status": {
    	  "type": "keyword"
        },
	"message": {
		  "type": "text"
	}
      }
    }
  }
}'

HTTP/1.1 200 OK

{"acknowledged":true}

curl -ivvk -H "Accept: application/json" -u username:password -X GET "https://localhost:9200/_cat/templates"

HTTP/1.1 200 OK

[{"name":"test_template","index_patterns":"[test-*]","order":"0","version":null,"composed_of":""}]

```

I then created the index, test-1, with a deliberate attempt to violate the intended mapping of **status** to keyword, by assigning an integer value to it:

```auto
curl -ivvk -H "Content-Type: application/json" -H "Accept: application/json" -u username:password -X POST "https://localhost:9200/test-1/_create/1" -d '
{
  "status": 7,
  "message": "This is a test."
}'

HTTP/1.1 201 Created

{"_index":"test-1","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

```

When I inspected the mapping that was applied to test-1, I saw:

```auto
curl -ivvk -u username:password -H "Accept: application/json" "https://localhost:9200/test-1/_mapping?pretty"

HTTP/1.1 200

{
  "test-1" : {
    "mappings" : {
      "properties" : {
        "message" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "status" : {
          "type" : "long"
        }
      }
    }
  }
}

```

I realized the template was ignored since status had type, long, instead of keyword. Can someone tell me what I should be doing?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [August 19, 2020, 8:47pm UTC](https://discuss.elastic.co/t/open-source-elasticsearch-does-not-use-template-in-index-creation/245673/2 "2020-08-19T20:47:15Z")

</div>

What is the output of \_cat/templates? Do you have any other templates that match the same pattern?

---

<div class="post-metadata">

### Author: ![hweber](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@hweber](https://discuss.elastic.co/u/hweber)
#### Post date: [August 19, 2020, 9:00pm UTC](https://discuss.elastic.co/t/open-source-elasticsearch-does-not-use-template-in-index-creation/245673/3 "2020-08-19T21:00:11Z")

</div>

> [@hweber](#):
>
> `[{"name":"test_template","index_patterns":"[test-*]","order":"0","version":null,"composed_of":""}]`

The output is exactly what I originally wrote, `[{"name":"test_template","index_patterns":"[test-*]","order":"0","version":null,"composed_of":""}]`. I used a pristine Elasticsearch that had no templates.

---

<div class="post-metadata">

### Author: ![hweber](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@hweber](https://discuss.elastic.co/u/hweber)
#### Post date: [August 20, 2020, 1:42pm UTC](https://discuss.elastic.co/t/open-source-elasticsearch-does-not-use-template-in-index-creation/245673/4 "2020-08-20T13:42:32Z")

</div>

It appears that the “template” name/value in my test\_template caused the problem. Removing it (moving its inner data to its level) allowed it to work.

---

<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 17, 2020, 1:42pm UTC](https://discuss.elastic.co/t/open-source-elasticsearch-does-not-use-template-in-index-creation/245673/5 "2020-09-17T13:42:51Z")

</div>

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