# Why the dynamic\_templates dose not work?

**URL:** <https://discuss.elastic.co/t/why-the-dynamic-templates-dose-not-work/7120>\
**Category:** Elasticsearch\
**Created:** [March 26, 2012, 8:09am UTC](https://discuss.elastic.co/t/why-the-dynamic-templates-dose-not-work/7120 "2012-03-26T08:09:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhouxiang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zhouxiang/32/2775_2.png) [@zhouxiang](https://discuss.elastic.co/u/zhouxiang)\
**Post date:** [March 26, 2012, 8:09am UTC](https://discuss.elastic.co/t/why-the-dynamic-templates-dose-not-work/7120/1 "2012-03-26T08:09:16Z")

</div>

my config  
{  
"data" : {  
"analysis" : {  
"analyzer" : {  
"ik" : {  
"type" :  
"org.elasticsearch.index.analysis.IkAnalyzerProvider"  
}  
}  
},  
"ad" : {  
"\_all" : {"enabled" : false},  
"\_id" : {"path" : "id"},  
"\_timestamp" : {"enabled" : false},  
"\_source" : {"enabled" : false},  
"properties" : {  
"id" : {"type" : "long", "index" : "yes", "store" :  
"yes"},  
"title" : {"type" : "string", "store" : "no",  
"indexAnalyzer" : "ik", "searchAnalyzer" : "ik", "include\_in\_all" :  
"false"},  
"description" : {"type" : "string", "store" : "no",  
"indexAnalyzer" : "ik", "searchAnalyzer" : "ik", "include\_in\_all" :  
"false"}  
},  
"dynamic\_templates" : [  
{  
"templates\_1" : {  
"match" : "\*\_i",  
"mapping" : {  
"type" : "long",  
"index" : "yes",  
"store" : "no",  
}  
}  
},  
{  
"templates\_2" : {  
"match" : "\*Date",  
"mapping" : {  
"type" : "Date",  
"index" : "yes",  
"store" : "no",  
"format" : "basic\_date\_time\_no\_millis",  
}  
}  
},  
{  
"templates\_3" : {  
"match" : "\*Time",  
"mapping" : {  
"type" : "Date",  
"index" : "yes",  
"store" : "no",  
"format" : "basic\_date\_time\_no\_millis",  
}  
}  
},  
{  
"templates\_4" : {  
"match" : "_Position",  
"mapping" : {  
"type" : "geo\_point",  
"index" : "yes",  
"store" : "no",  
}  
}  
},  
{  
"templates\_5" : {  
"match" : "_",  
"mapping" : {  
"type" : "string",  
"index" : "no",  
"store" : "no",  
}  
}  
},  
]  
}  
}  
}

when i add a doc under data/ad?but the dynamic templates dose not work.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 27, 2012, 1:04pm UTC](https://discuss.elastic.co/t/why-the-dynamic-templates-dose-not-work/7120/2 "2012-03-27T13:04:52Z")

</div>

You need to place the dynamic templates in the mapping definition, not the  
index settings. You can place it under a _default_ mapping name to apply to  
all mappings. Thats why the config is under the root mapping type:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html).

On Mon, Mar 26, 2012 at 10:09 AM, shinezhou [zhouxiang@baixing.com](mailto:zhouxiang@baixing.com) wrote:

> my config  
> {  
> "data" : {  
> "analysis" : {  
> "analyzer" : {  
> "ik" : {  
> "type" :  
> "org.elasticsearch.index.analysis.IkAnalyzerProvider"  
> }  
> }  
> },  
> "ad" : {  
> "\_all" : {"enabled" : false},  
> "\_id" : {"path" : "id"},  
> "\_timestamp" : {"enabled" : false},  
> "\_source" : {"enabled" : false},  
> "properties" : {  
> "id" : {"type" : "long", "index" : "yes", "store" :  
> "yes"},  
> "title" : {"type" : "string", "store" : "no",  
> "indexAnalyzer" : "ik", "searchAnalyzer" : "ik", "include\_in\_all" :  
> "false"},  
> "description" : {"type" : "string", "store" : "no",  
> "indexAnalyzer" : "ik", "searchAnalyzer" : "ik", "include\_in\_all" :  
> "false"}  
> },  
> "dynamic\_templates" : [  
> {  
> "templates\_1" : {  
> "match" : "\*\_i",  
> "mapping" : {  
> "type" : "long",  
> "index" : "yes",  
> "store" : "no",  
> }  
> }  
> },  
> {  
> "templates\_2" : {  
> "match" : "\*Date",  
> "mapping" : {  
> "type" : "Date",  
> "index" : "yes",  
> "store" : "no",  
> "format" : "basic\_date\_time\_no\_millis",  
> }  
> }  
> },  
> {  
> "templates\_3" : {  
> "match" : "\*Time",  
> "mapping" : {  
> "type" : "Date",  
> "index" : "yes",  
> "store" : "no",  
> "format" : "basic\_date\_time\_no\_millis",  
> }  
> }  
> },  
> {  
> "templates\_4" : {  
> "match" : "_Position",  
> "mapping" : {  
> "type" : "geo\_point",  
> "index" : "yes",  
> "store" : "no",  
> }  
> }  
> },  
> {  
> "templates\_5" : {  
> "match" : "_",  
> "mapping" : {  
> "type" : "string",  
> "index" : "no",  
> "store" : "no",  
> }  
> }  
> },  
> ]  
> }  
> }  
> }
> 
> when i add a doc under data/ad?but the dynamic templates dose not 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:** [July 6, 2017, 3:34am UTC](https://discuss.elastic.co/t/why-the-dynamic-templates-dose-not-work/7120/3 "2017-07-06T03:34:40Z")

</div>


