# How to set default mapping for string as "not\_analyzed"? No luck with dynamic\_templates

**URL:** <https://discuss.elastic.co/t/how-to-set-default-mapping-for-string-as-not-analyzed-no-luck-with-dynamic-templates/381>\
**Category:** Elasticsearch\
**Created:** [May 8, 2015, 8:27am UTC](https://discuss.elastic.co/t/how-to-set-default-mapping-for-string-as-not-analyzed-no-luck-with-dynamic-templates/381 "2015-05-08T08:27:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [May 8, 2015, 8:27am UTC](https://discuss.elastic.co/t/how-to-set-default-mapping-for-string-as-not-analyzed-no-luck-with-dynamic-templates/381/1 "2015-05-08T08:27:33Z")

</div>

How to set default mapping for string as "not\_analyzed"? No luck with dynamic\_templates

I tried running this below template first in my CURL  
PUT /my\_index  
{  
"mappings": {  
"my\_type": {  
"dynamic\_templates": [  
{ "notanalyzed": {  
"match": "\*",  
"match\_mapping\_type": "string",  
"mapping": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
]  
}  
}  
}

Then with same index and type , i created a document. It seems the string value is not set to "not\_analyzed" by default

Any one is having step by step solution for this or I am missing something

---

<div class="post-metadata">

**Author:** ![Allan\_Mitchell](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@Allan\_Mitchell](https://discuss.elastic.co/u/Allan_Mitchell)\
**Post date:** [May 8, 2015, 11:04am UTC](https://discuss.elastic.co/t/how-to-set-default-mapping-for-string-as-not-analyzed-no-luck-with-dynamic-templates/381/2 "2015-05-08T11:04:53Z")

</div>

Hi

This works for me

PUT /\_template/mytesttemplate  
{  
"template": "something\*",  
"order": 1,  
"settings": {  
"number\_of\_shards": 5  
},  
"mappings": {  
"mytype": {  
"dynamic\_templates": [  
{  
"string\_fields": {  
"mapping": {  
"index": "not\_analyzed",  
"type": "string"  
},  
"match\_mapping\_type": "string",  
"match": "\*"  
}  
}  
],  
"\_all": {  
"enabled": false  
}  
}  
}  
}

PUT /something1

GET /something1/\_mapping

POST /something1/mytype/1  
{  
"text" : "This is a string",  
"c2": "so is this"

}

GET /something1/mytype/\_search  
{  
"query": {  
"match": {  
"text": "This is a string"  
}  
}  
}

---

<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, 12:15am UTC](https://discuss.elastic.co/t/how-to-set-default-mapping-for-string-as-not-analyzed-no-luck-with-dynamic-templates/381/3 "2017-07-06T00:15:04Z")

</div>


