# \[version 7.1.1\] When I set the type of some fields to 'keyword' by ES mapping , it doesn't work

**URL:** <https://discuss.elastic.co/t/version-7-1-1-when-i-set-the-type-of-some-fields-to-keyword-by-es-mapping-it-doesnt-work/212874>\
**Category:** Elasticsearch\
**Created:** [December 23, 2019, 5:08pm UTC](https://discuss.elastic.co/t/version-7-1-1-when-i-set-the-type-of-some-fields-to-keyword-by-es-mapping-it-doesnt-work/212874 "2019-12-23T17:08:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![francis-oyc](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@francis-oyc](https://discuss.elastic.co/u/francis-oyc)\
**Post date:** [December 23, 2019, 5:08pm UTC](https://discuss.elastic.co/t/version-7-1-1-when-i-set-the-type-of-some-fields-to-keyword-by-es-mapping-it-doesnt-work/212874/1 "2019-12-23T17:08:18Z")

</div>

Recently, I have built an ELK system, I wat to set the type of some fields to 'keyword' by ES mapping , but it doesn't work.Here is my ES mapping :  
PUT /\_template/francis-template  
{  
"index\_patterns": ["_"],  
"version" : 60001,  
"order": "10",  
"settings": {  
"index": {  
"number\_of\_shards": "1",  
"number\_of\_replicas": "0",  
"refresh\_interval": "10s"  
}  
},  
"mappings": {  
"dynamic\_templates": [  
{  
"string\_fields": {  
"match": "_",  
"match\_mapping\_type": "string",  
"mapping": {  
"type": "keyword"  
}  
}  
},  
{  
"dates": {  
"match": "\*Time",  
"match\_mapping\_type": "string",  
"mapping": {  
"type": "date",  
"format": "yyyy-MM-dd HH:mm:ss.SSS"  
}  
}  
},  
{  
"dates": {  
"match": "\*Date",  
"match\_mapping\_type": "string",  
"mapping": {  
"type": "date",  
"format": "yyyy-MM-dd HH:mm:ss.SSS"  
}  
}  
}  
],  
"properties": {  
"@timestamp": {  
"type": "date"  
},  
"appName": {  
"type": "keyword"  
},  
"className": {  
"type": "keyword"  
},  
"exportable": {  
"type": "keyword"  
},  
"logLevel": {  
"type": "keyword"  
},  
"message": {  
"type": "keyword"  
},  
"parentId": {  
"type": "keyword"  
},  
"pid": {  
"type": "keyword"  
},  
"spanId": {  
"type": "keyword"  
},  
"thread": {  
"type": "keyword"  
},  
"traceId": {  
"type": "keyword"  
}  
}  
}  
}  
}

after put the mapping , I deleted all the indexes and then created a new index, when I cliked the new index's mapping , I found my settings doesn't work. Here is the screen shot :

 ![微信图片_20191224010330](https://us1.discourse-cdn.com/elastic/original/3X/4/a/4abe89402f452fd406761dd25fd0a143be0a71bd.png)  
For example, I just want to set the type of appName to 'keyword' , but it is still 'text', I don't how to solve it now, please help me , thanks !

---

<div class="post-metadata">

**Author:** ![HenningAndersen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henningandersen/32/48188_2.png) [@HenningAndersen](https://discuss.elastic.co/u/HenningAndersen)\
**Post date:** [December 23, 2019, 6:08pm UTC](https://discuss.elastic.co/t/version-7-1-1-when-i-set-the-type-of-some-fields-to-keyword-by-es-mapping-it-doesnt-work/212874/2 "2019-12-23T18:08:06Z")

</div>

@francis-oyc,

updating the type of fields is not possible, since all existing data would not be indexed in the way reflected by the new type.

Instead you would have to [reindex](https://www.elastic.co/guide/en/elasticsearch/reference/7.1/docs-reindex.html) your data to a new index with the corrected mapping.

Notice that text data is by default indexed both as text and keyword, thus you can use the `appName.keyword` field for an exact match keyword query.

---

<div class="post-metadata">

**Author:** ![francis-oyc](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@francis-oyc](https://discuss.elastic.co/u/francis-oyc)\
**Post date:** [December 24, 2019, 1:09am UTC](https://discuss.elastic.co/t/version-7-1-1-when-i-set-the-type-of-some-fields-to-keyword-by-es-mapping-it-doesnt-work/212874/4 "2019-12-24T01:09:59Z")

</div>

If I don't want to reindex my data to a new index ，when I set the output properties for Logstash ，could I specify a custom template to overrite the default template ？And does it work？

---

<div class="post-metadata">

**Author:** ![francis-oyc](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@francis-oyc](https://discuss.elastic.co/u/francis-oyc)\
**Post date:** [December 24, 2019, 1:41am UTC](https://discuss.elastic.co/t/version-7-1-1-when-i-set-the-type-of-some-fields-to-keyword-by-es-mapping-it-doesnt-work/212874/5 "2019-12-24T01:41:15Z")

</div>

My step is : First， I put the mapping in Kibana. Second， I deleted all existing indexes，and then created a new index. So I don't think there's any data existed. My purpose is : Logs outputted from Logstash to Elasticsearch，index mapping would be created according to the type that I set，but it's not.

---

<div class="post-metadata">

**Author:** ![francis-oyc](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@francis-oyc](https://discuss.elastic.co/u/francis-oyc)\
**Post date:** [December 24, 2019, 9:34am UTC](https://discuss.elastic.co/t/version-7-1-1-when-i-set-the-type-of-some-fields-to-keyword-by-es-mapping-it-doesnt-work/212874/6 "2019-12-24T09:34:55Z")

</div>

I have solved this problem , thanks !

---

<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:** [January 21, 2020, 9:34am UTC](https://discuss.elastic.co/t/version-7-1-1-when-i-set-the-type-of-some-fields-to-keyword-by-es-mapping-it-doesnt-work/212874/7 "2020-01-21T09:34:55Z")

</div>

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