# Index templates not working in ES 2.4

**URL:** <https://discuss.elastic.co/t/index-templates-not-working-in-es-2-4/63696>\
**Category:** Elasticsearch\
**Created:** [October 24, 2016, 1:01am UTC](https://discuss.elastic.co/t/index-templates-not-working-in-es-2-4/63696 "2016-10-24T01:01:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaung/32/11165_2.png) [@kaung](https://discuss.elastic.co/u/kaung)\
**Post date:** [October 24, 2016, 1:01am UTC](https://discuss.elastic.co/t/index-templates-not-working-in-es-2-4/63696/1 "2016-10-24T01:01:17Z")

</div>

I have the following index templates that have been working up until Elasticsearch 2.3.4. After I upgraded my Elasticsearch to 2.4, it seem to have broken. I am out of idea where I could be doing wrong. Some help is really appreciated.

**step-1** : I have inserted and verified that the following index template exists:  
`curl "http://localhost:9200/_template"`

`{"stats":{"order":0,"template":"stats-*",...,"mappings":{"_default_":{"dynamic_templates":[...{"timestamp_fields":{"match_pattern":"regex","mapping":{"type":"date","doc_values":true},"match":".*[tT]imestamp"}}],"date_detection":false,...}`  
(full index in Appendix)

**step-2** : I understand that index templates are only applied during index creation. So I deleted all existing indices first.  
`curl -XDELETE "http://localhost:9200/stats-*"`

**Step-3** : Then, I insert the data using Bulk API.  
`curl -XPOST "http://localhost:9200/_bulk" --data-binary @data.json`  
data.json  
`{"index":{"_index":"stats-2016.10","_type":"MyType","_id":"xxxxyyyy"}}`  
`{"@version":"1","@timestamp":"2016-10-30T06:00:00Z",....}`

**Step-4** : Then, I checked the field data type (of @timestamp) as follows:  
`curl -XGET "http://localhost:9200/stats-2016.10/_mapping/MyType/field/@timestamp"`

My understanding is that the bulk inserts should cause the indexes to be automatically created and since the index name (stats-2016.10) matches the index template (stats-\*), the template should have applied. Then, I expect that fields that end with "[tT]imestamp" should have "date" type mapping. Therefore,

Expected (was seen in ES 2.3.4):

> {  
> "stats-2016.10": {  
> "mappings": {  
> "MyType": {  
> "@timestamp": {  
> "full\_name": "@timestamp",  
> "mapping": {  
> "@timestamp": {  
> "type": "date",  
> "format": "strict\_date\_optional\_time||epoch\_millis"  
> }  
> }  
> }  
> }  
> }  
> }  
> }

But, Actual (seen in ES 2.4):

> {  
> "stats-2016.10": {  
> "mappings": {  
> "MyType": {  
> "@timestamp": {  
> "full\_name": "@timestamp",  
> "mapping": {  
> "@timestamp": {  
> "type": "string",  
> "fields": {  
> "raw": {  
> "type": "string",  
> "index": "not\_analyzed"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }

All the above have been working fine until until ES 2.3.4. I upgrade my ES to version 2.4 and it stops working. Did I miss some configurations that should do but didn't? what else could be wrong? Thanks in advance.

Appendix:  
full index template  
`curl "http://localhost:9200/_template"`  
`{"stats":{"order":0,"template":"stats-*","settings":{"index":{"number_of_shards":"2","number_of_replicas":"0","refresh_interval":"10s"}},"mappings":{"_default_":{"dynamic_templates":[{"string_fields":{"mapping":{"fields":{"raw":{"index":"not_analyzed","omit_norms":true,"type":"string","doc_values":true}}},"match_mapping_type":"string","match":"*","index":"analyzed"}},{"number_fields":{"mapping":{"doc_values":true},"match_mapping_type":"long","match":"*"}},{"boolean_fields":{"mapping":{"doc_values":true},"match_mapping_type":"boolean","match":"*"}},{"timestamp_fields":{"match_pattern":"regex","mapping":{"type":"date","doc_values":true},"match":".*[tT]imestamp"}}],"date_detection":false,"properties":{"@version":{"index":"not_analyzed","type":"string"}}}},"aliases":{}}}`

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [October 24, 2016, 3:37am UTC](https://discuss.elastic.co/t/index-templates-not-working-in-es-2-4/63696/2 "2016-10-24T03:37:24Z")

</div>

Hi @kaung

You should move `timestamp_fields` to the first in dynamic\_templates, I think.  
See:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#dynamic-templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#dynamic-templates)

---

<div class="post-metadata">

**Author:** ![kaung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaung/32/11165_2.png) [@kaung](https://discuss.elastic.co/u/kaung)\
**Post date:** [October 24, 2016, 4:51am UTC](https://discuss.elastic.co/t/index-templates-not-working-in-es-2-4/63696/3 "2016-10-24T04:51:33Z")

</div>

@johtani. Thanks and Indeed, swapping the order fixes it. Also since the doc page you mentioned says "Templates are processed in order — the first matching template wins." So that makes sense.

I am curious why it has been working from ES 1.7 thru 2.3.x though. I re-did the test to be sure. Up until ES 2.3.5, the mapping for "[tT]imestamp fields was "date" regardless of the ordering in the index template. It seems to me there used to be something else apart from which template appear first.

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [October 24, 2016, 6:56am UTC](https://discuss.elastic.co/t/index-templates-not-working-in-es-2-4/63696/4 "2016-10-24T06:56:56Z")

</div>

Did you use exactly same template? Did you set `date_detection:false`?  
I didn't read the code honestly, I just would like to ask it.

---

<div class="post-metadata">

**Author:** ![kaung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaung/32/11165_2.png) [@kaung](https://discuss.elastic.co/u/kaung)\
**Post date:** [October 24, 2016, 7:35am UTC](https://discuss.elastic.co/t/index-templates-not-working-in-es-2-4/63696/5 "2016-10-24T07:35:23Z")

</div>

Yep. It's exactly the same template. `date_detection:false`. Tested with the same 4 steps listed in my post .

---

<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:** [July 5, 2017, 10:10pm UTC](https://discuss.elastic.co/t/index-templates-not-working-in-es-2-4/63696/6 "2017-07-05T22:10:17Z")

</div>


