# Map fields to String

**URL:** <https://discuss.elastic.co/t/map-fields-to-string/23090>\
**Category:** Elasticsearch\
**Created:** [April 3, 2015, 10:39pm UTC](https://discuss.elastic.co/t/map-fields-to-string/23090 "2015-04-03T22:39:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grayson\_Cash](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@Grayson\_Cash](https://discuss.elastic.co/u/Grayson_Cash)\
**Post date:** [April 3, 2015, 10:39pm UTC](https://discuss.elastic.co/t/map-fields-to-string/23090/1 "2015-04-03T22:39:44Z")

</div>

I'm wanting to map all fields in my indices to a String. I understand that  
you do this with a mapping but I'm having trouble constructing the correct  
structure. If I don't, there will be collisions with a field "Code" being  
either an integer or string with my given input.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/70e36b0c-3330-42f2-8e67-7f61e2748fc1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/70e36b0c-3330-42f2-8e67-7f61e2748fc1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [April 4, 2015, 5:56am UTC](https://discuss.elastic.co/t/map-fields-to-string/23090/2 "2015-04-04T05:56:25Z")

</div>

Hello Grayson ,

You can use \_default  
[http://www.elastic.co/guide/en/elasticsearch/reference/1.x/index-modules-mapper.html#\_default\_mapping](http://www.elastic.co/guide/en/elasticsearch/reference/1.x/index-modules-mapper.html#_default_mapping)  
\_  
[http://www.elastic.co/guide/en/elasticsearch/reference/1.x/index-modules-mapper.html#\_default\_mapping](http://www.elastic.co/guide/en/elasticsearch/reference/1.x/index-modules-mapper.html#_default_mapping)  
to mark all types under a type.  
Then you can use dynamic field template  
[http://www.elastic.co/guide/en/elasticsearch/guide/master/custom-dynamic-mapping.html#dynamic-templates](http://www.elastic.co/guide/en/elasticsearch/guide/master/custom-dynamic-mapping.html#dynamic-templates)  
to impose this rule.  
In your case you can use match\_mapping\_type to identify all numbers and  
impose string mapping.  
Or even apply to \* pattern should also work , with the top being more  
accurate.

Thanks  
Vineeth Mohan,  
Elasticsearch consultant,  
[qbox.io](http://qbox.io) ( Elasticsearch service provider [http://qbox.io/](http://qbox.io/))

On Sat, Apr 4, 2015 at 4:09 AM, Grayson Cash [cashgl92@gmail.com](mailto:cashgl92@gmail.com) wrote:

> I'm wanting to map all fields in my indices to a String. I understand that  
> you do this with a mapping but I'm having trouble constructing the correct  
> structure. If I don't, there will be collisions with a field "Code" being  
> either an integer or string with my given input.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/70e36b0c-3330-42f2-8e67-7f61e2748fc1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/70e36b0c-3330-42f2-8e67-7f61e2748fc1%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/70e36b0c-3330-42f2-8e67-7f61e2748fc1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/70e36b0c-3330-42f2-8e67-7f61e2748fc1%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nSCjQG8g51m%3DgXkBb71t4Y2Yw\_we19D%2BTp904eawZfOg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nSCjQG8g51m%3DgXkBb71t4Y2Yw_we19D%2BTp904eawZfOg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:21am UTC](https://discuss.elastic.co/t/map-fields-to-string/23090/3 "2017-07-06T00:21:43Z")

</div>


