# Problems with dynamic mapping

**URL:** <https://discuss.elastic.co/t/problems-with-dynamic-mapping/11041>\
**Category:** Elasticsearch\
**Created:** [March 6, 2013, 7:41pm UTC](https://discuss.elastic.co/t/problems-with-dynamic-mapping/11041 "2013-03-06T19:41:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_6](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@Jason\_6](https://discuss.elastic.co/u/Jason_6)\
**Post date:** [March 6, 2013, 7:41pm UTC](https://discuss.elastic.co/t/problems-with-dynamic-mapping/11041/1 "2013-03-06T19:41:17Z")

</div>

HI folks,

We are using elastic search index a bunch of JSON documents which all have \*  
roughly\* the same structure, but there are some variations which is causing  
headaches with dynamic mapping. Specifically fields in the document that,  
when first observed by elastic search, were numeric types (and therefore  
mapped as numeric by ES), but in later documents these same fields have  
string values. This results in a NumberFormaException in ES and the  
document cannot be indexed.

A couple of caveats:

- We don't control the documents. They come from an external source and  
are "supposed" to conform to a standard, but often don't
- We can't plausibly provide a mapping for the entire document. They  
are huge (in structure) and not always consistent.

We do provide a custom mapping for the fields we really care about  
filtering on, but the others we we want indexed but care a little less  
about how we would filter on these values (if at all).

Is there a way to tell elastic search to treat any new field it sees as a  
string? I.e., don't infer the type for a new field, just treat it as a  
string?

Thanks!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [March 6, 2013, 10:22pm UTC](https://discuss.elastic.co/t/problems-with-dynamic-mapping/11041/2 "2013-03-06T22:22:25Z")

</div>

You can use dynamic templates to control how dynamic fields (the ones not  
explicitly defined in your mapping) are mapped:

[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)(scroll  
down for dynamic templates)

--  
Ivan

On Wed, Mar 6, 2013 at 11:41 AM, Jason [jason.polites@getsocialize.com](mailto:jason.polites@getsocialize.com)wrote:

> HI folks,
> 
> We are using Elasticsearch index a bunch of JSON documents which all have  
> _roughly_ the same structure, but there are some variations which is  
> causing headaches with dynamic mapping. Specifically fields in the  
> document that, when first observed by Elasticsearch, were numeric types  
> (and therefore mapped as numeric by ES), but in later documents these same  
> fields have string values. This results in a NumberFormaException in ES  
> and the document cannot be indexed.
> 
> A couple of caveats:
> 
> - We don't control the documents. They come from an external source  
> and are "supposed" to conform to a standard, but often don't
> - We can't plausibly provide a mapping for the entire document. They  
> are huge (in structure) and not always consistent.
> 
> We do provide a custom mapping for the fields we really care about  
> filtering on, but the others we we want indexed but care a little less  
> about how we would filter on these values (if at all).
> 
> Is there a way to tell Elasticsearch to treat any new field it sees as a  
> string? I.e., don't infer the type for a new field, just treat it as a  
> string?
> 
> Thanks!
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jason\_6](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@Jason\_6](https://discuss.elastic.co/u/Jason_6)\
**Post date:** [March 6, 2013, 10:24pm UTC](https://discuss.elastic.co/t/problems-with-dynamic-mapping/11041/3 "2013-03-06T22:24:27Z")

</div>

Perfect. Exactly what I needed. Thanks! (not sure how I missed this)

On Wed, Mar 6, 2013 at 2:22 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> You can use dynamic templates to control how dynamic fields (the ones not  
> explicitly defined in your mapping) are mapped:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)(scroll down for dynamic templates)
> 
> --  
> Ivan
> 
> On Wed, Mar 6, 2013 at 11:41 AM, Jason [jason.polites@getsocialize.com](mailto:jason.polites@getsocialize.com)wrote:
> 
> > HI folks,
> > 
> > We are using Elasticsearch index a bunch of JSON documents which all  
> > have _roughly_ the same structure, but there are some variations which  
> > is causing headaches with dynamic mapping. Specifically fields in the  
> > document that, when first observed by Elasticsearch, were numeric types  
> > (and therefore mapped as numeric by ES), but in later documents these same  
> > fields have string values. This results in a NumberFormaException in ES  
> > and the document cannot be indexed.
> > 
> > A couple of caveats:
> > 
> > - We don't control the documents. They come from an external source  
> > and are "supposed" to conform to a standard, but often don't
> > - We can't plausibly provide a mapping for the entire document. They  
> > are huge (in structure) and not always consistent.
> > 
> > We do provide a custom mapping for the fields we really care about  
> > filtering on, but the others we we want indexed but care a little less  
> > about how we would filter on these values (if at all).
> > 
> > Is there a way to tell Elasticsearch to treat any new field it sees as a  
> > string? I.e., don't infer the type for a new field, just treat it as a  
> > string?
> > 
> > Thanks!
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/gIcNdmIXo\_Y/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/gIcNdmIXo_Y/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Jason Polites\*  
\*  
Socialize Inc\*  
\*  
[Jason.Polites@GetSocialize.com](mailto:Jason.Polites@GetSocialize.com) [jason.polites@getsocialize.com](mailto:jason.polites@getsocialize.com)\*  
\*153 Townsend St #9057  
San Francisco  
CA 94107

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:47am UTC](https://discuss.elastic.co/t/problems-with-dynamic-mapping/11041/4 "2017-07-06T02:47:55Z")

</div>


