# Does Elasticsearch 2.3.1 support user defined dynamic template?

**URL:** <https://discuss.elastic.co/t/does-elasticsearch-2-3-1-support-user-defined-dynamic-template/48699>\
**Category:** Elasticsearch\
**Created:** [April 28, 2016, 3:15pm UTC](https://discuss.elastic.co/t/does-elasticsearch-2-3-1-support-user-defined-dynamic-template/48699 "2016-04-28T15:15:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharon.c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharon.c/32/16076_2.png) [@sharon.c](https://discuss.elastic.co/u/sharon.c)\
**Post date:** [April 28, 2016, 3:15pm UTC](https://discuss.elastic.co/t/does-elasticsearch-2-3-1-support-user-defined-dynamic-template/48699/1 "2016-04-28T15:15:45Z")

</div>

Because my project is mainly for aggregation (not for searching), I want to make all the string type fields by default not \_analyzed. I used to use Elasticsearch from 1.7 to 2.2, they all support user defined dynamic\_template, but when I switch to Elasticsearch 2.3, according to my test, it does not support user defined dynamic\_template.

This is my logstash .conf file, I used this .conf file for two tests, one is using dynamic\_template, another is using root level properties definition to define string fields to be not analysed.

> 

input{stdin{}}  
filter {  
json { source =\> "message" }  
}  
output {  
stdout { codec =\> rubydebug }  
elasticsearch {  
hosts =\> "staging-elkstack:9200"  
index =\> "template\_test"  
template\_name =\> "elkstats\_template"  
}  
}

sample input

> 

{ "longitude":-73.758, "latitude":41.0291}

Test 1:  
Use root level properties definition to define host and message, they are not\_analyzed as I expected

> 

curl -XPUT '[http://staging-elkstack:9200/\_template/elkstats\_template](http://staging-elkstack:9200/_template/elkstats_template)' -d '  
{  
"order" : 3,  
"template": "template\_test\*",  
"mappings" : {  
"log" : {  
"\_all" : {"enabled" : false, "omit\_norms" : true},  
"properties" : {  
"@timestamp": { "type": "date", "doc\_values" : true },  
"@version": { "type": "string", "index": "not\_analyzed", "doc\_values" : true },  
"message": { "type": "string", "index": "not\_analyzed", "doc\_values" : true },  
"host": { "type": "string", "index": "not\_analyzed", "doc\_values" : true }  
}  
}  
}  
}  
'

As you can see in the kibana settings interface, now the message, and host fields are not\_analyzed

 ![](https://us1.discourse-cdn.com/elastic/original/2X/4/44bcfd4b1f176e0f1ddda2cd5f1d7a5538fa4d05.png)

Test 2:  
I used this script to define the dynamic\_template for strings to be not\_analyzed in general

> 

curl -XPUT '[http://staging-elkstack:9200/\_template/elkstats\_template](http://staging-elkstack:9200/_template/elkstats_template)' -d '  
{  
"order" : 3,  
"template": "template\_test\*",  
"mappings" : {  
"log" : {  
"\_all" : {"enabled" : false, "omit\_norms" : true},  
"dynamic\_templates" : [ {  
"message\_field" : {  
"match" : "message",  
"match\_mapping\_type" : "string",  
"mapping" : {  
"type" : "string", "index" : "not\_analyzed", "omit\_norms" : true  
}  
}  
}, {  
"string\_fields" : {  
"match" : "\*",  
"match\_mapping\_type" : "string",  
"mapping" : {  
"type" : "string", "index" : "not\_analyzed", "omit\_norms" : true  
}  
}  
}  
],  
"properties" : {  
"@timestamp": { "type": "date", "doc\_values" : true },  
"@version": { "type": "string", "index": "not\_analyzed", "doc\_values" : true }  
}  
}  
}  
}  
'

As you can see, the host and message fields are still analyzed (which means that the definition in "dynamic\_template" section is not used here)

 ![](https://us1.discourse-cdn.com/elastic/original/2X/3/319b9be22ab9f18d4843d8698024b028e1f5645e.png)

I really need the dynamic\_template settings to ensure string type fields are not\_analyzed, what can I do to make it work?

---

<div class="post-metadata">

**Author:** ![sharon.c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharon.c/32/16076_2.png) [@sharon.c](https://discuss.elastic.co/u/sharon.c)\
**Post date:** [May 11, 2016, 7:32pm UTC](https://discuss.elastic.co/t/does-elasticsearch-2-3-1-support-user-defined-dynamic-template/48699/2 "2016-05-11T19:32:58Z")

</div>

The data I injected has a field "type" with the value "logs"  
and in curl, the mapping definition I wrote is that mapping name is "log"  
so "log" and "logs" do not match.  
That's why the template is not applied.

---

<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:52pm UTC](https://discuss.elastic.co/t/does-elasticsearch-2-3-1-support-user-defined-dynamic-template/48699/3 "2017-07-05T22:52:25Z")

</div>


