# How can I store 2 different data types in same field of 2 different document?

**URL:** <https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532>\
**Category:** Elasticsearch\
**Created:** [January 8, 2015, 9:14am UTC](https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532 "2015-01-08T09:14:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paresh\_Behede](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paresh_behede/32/937_2.png) [@Paresh\_Behede](https://discuss.elastic.co/u/Paresh_Behede)\
**Post date:** [January 8, 2015, 9:14am UTC](https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532/1 "2015-01-08T09:14:16Z")

</div>

Hi,

I have requirement of storing document in elastic search which will have  
dynamic fields + those fields could have different data types values...

For e.g.,  
Document 1 could have age field with value = 32, so when I would insert 1st  
document in ES my index mapping will get created and age will be mapped to  
Integer/Long

Now if I get age = 32.5 in another document ES will throw me exception of  
data type mismatch...

Can you suggest what can I do to handle such scenario?

As workaround we are creating different fields for different data types  
like age.long / age.double but this also won't work if I have to do sorting  
over age field...

Kindly suggest...

Thanks in advance,  
Paresh Behede

--  
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/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [January 8, 2015, 1:43pm UTC](https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532/2 "2015-01-08T13:43:06Z")

</div>

Hi Paresh,

If you want to sort on the field, I think it has to be the same type. So if  
you make everything a double, it should work for all numeric fields. To do  
that, you can use dynamic templates  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#\_dynamic\_templates](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#_dynamic_templates).  
For example if you have this:

"mappings" : {  
"_default_" : {  
"dynamic\_templates" : [ {  
"long\_to\_float" : {  
"match" : "\*",  
"match\_mapping\_type" : "long",  
"mapping" : {  
"type" : "float"  
}  
}  
} ]  
}  
}

And add a new field with value=32, the field would be mapped as float  
instead of long.

## Best regards, Radu

Performance Monitoring \* Log Analytics \* Search Analytics  
Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)

On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede [paresh2711@gmail.com](mailto:paresh2711@gmail.com) wrote:

> Hi,
> 
> I have requirement of storing document in Elasticsearch which will have  
> dynamic fields + those fields could have different data types values...
> 
> For e.g.,  
> Document 1 could have age field with value = 32, so when I would insert  
> 1st document in ES my index mapping will get created and age will be mapped  
> to Integer/Long
> 
> Now if I get age = 32.5 in another document ES will throw me exception of  
> data type mismatch...
> 
> Can you suggest what can I do to handle such scenario?
> 
> As workaround we are creating different fields for different data types  
> like age.long / age.double but this also won't work if I have to do sorting  
> over age field...
> 
> Kindly suggest...
> 
> Thanks in advance,  
> Paresh Behede
> 
> --  
> 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/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%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/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_%2BPsCYxCHu7\_ErZVw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_09uEGnDtJegPyZ-FY%2BUeCzDs_N1_%2BPsCYxCHu7_ErZVw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 8, 2015, 2:01pm UTC](https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532/3 "2015-01-08T14:01:51Z")

</div>

Very nice Radu. I love this trick. 🙂

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 8 janv. 2015 à 14:43, Radu Gheorghe [radu.gheorghe@sematext.com](mailto:radu.gheorghe@sematext.com) a écrit :
> 
> Hi Paresh,
> 
> If you want to sort on the field, I think it has to be the same type. So if you make everything a double, it should work for all numeric fields. To do that, you can use dynamic templates [http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#\_dynamic\_templates](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#_dynamic_templates). For example if you have this:
> 
> "mappings" : {  
> "_default_" : {  
> "dynamic\_templates" : [ {  
> "long\_to\_float" : {  
> "match" : "\*",  
> "match\_mapping\_type" : "long",  
> "mapping" : {  
> "type" : "float"  
> }  
> }  
> } ]  
> }  
> }
> 
> And add a new field with value=32, the field would be mapped as float instead of long.
> 
> ## Best regards, Radu
> 
> Performance Monitoring \* Log Analytics \* Search Analytics  
> Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/) [http://sematext.com/](http://sematext.com/)  
> On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede \<[paresh2711@gmail.com](mailto:paresh2711@gmail.com) [mailto:paresh2711@gmail.com](mailto:paresh2711@gmail.com)\> wrote:  
> Hi,
> 
> I have requirement of storing document in Elasticsearch which will have dynamic fields + those fields could have different data types values...
> 
> For e.g.,  
> Document 1 could have age field with value = 32, so when I would insert 1st document in ES my index mapping will get created and age will be mapped to Integer/Long
> 
> Now if I get age = 32.5 in another document ES will throw me exception of data type mismatch...
> 
> Can you suggest what can I do to handle such scenario?
> 
> As workaround we are creating different fields for different data types like age.long / age.double but this also won't work if I have to do sorting over age field...
> 
> Kindly suggest...
> 
> Thanks in advance,  
> Paresh Behede
> 
> --  
> 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) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [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) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_%2BPsCYxCHu7\_ErZVw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_09uEGnDtJegPyZ-FY%2BUeCzDs_N1_%2BPsCYxCHu7_ErZVw%40mail.gmail.com) [https://groups.google.com/d/msgid/elasticsearch/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_%2BPsCYxCHu7\_ErZVw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_09uEGnDtJegPyZ-FY%2BUeCzDs_N1_%2BPsCYxCHu7_ErZVw%40mail.gmail.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [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/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [January 8, 2015, 3:41pm UTC](https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532/4 "2015-01-08T15:41:40Z")

</div>

Thanks, David! I had no idea it works until... about one hour ago 🙂

--  
Performance Monitoring \* Log Analytics \* Search Analytics  
Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)

On Thu, Jan 8, 2015 at 4:01 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Very nice Radu. I love this trick. 🙂
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> [http://Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 8 janv. 2015 à 14:43, Radu Gheorghe [radu.gheorghe@sematext.com](mailto:radu.gheorghe@sematext.com) a  
> écrit :
> 
> Hi Paresh,
> 
> If you want to sort on the field, I think it has to be the same type. So  
> if you make everything a double, it should work for all numeric fields. To  
> do that, you can use dynamic templates  
> [http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#\_dynamic\_templates](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#_dynamic_templates).  
> For example if you have this:
> 
> "mappings" : {  
> "_default_" : {  
> "dynamic\_templates" : [ {  
> "long\_to\_float" : {  
> "match" : "\*",  
> "match\_mapping\_type" : "long",  
> "mapping" : {  
> "type" : "float"  
> }  
> }  
> } ]  
> }  
> }
> 
> And add a new field with value=32, the field would be mapped as float  
> instead of long.
> 
> ## Best regards, Radu
> 
> Performance Monitoring \* Log Analytics \* Search Analytics  
> Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)
> 
> On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede [paresh2711@gmail.com](mailto:paresh2711@gmail.com)  
> wrote:
> 
> > Hi,
> > 
> > I have requirement of storing document in Elasticsearch which will have  
> > dynamic fields + those fields could have different data types values...
> > 
> > For e.g.,  
> > Document 1 could have age field with value = 32, so when I would insert  
> > 1st document in ES my index mapping will get created and age will be mapped  
> > to Integer/Long
> > 
> > Now if I get age = 32.5 in another document ES will throw me exception of  
> > data type mismatch...
> > 
> > Can you suggest what can I do to handle such scenario?
> > 
> > As workaround we are creating different fields for different data types  
> > like age.long / age.double but this also won't work if I have to do sorting  
> > over age field...
> > 
> > Kindly suggest...
> > 
> > Thanks in advance,  
> > Paresh Behede
> > 
> > --  
> > 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/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%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/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_%2BPsCYxCHu7\_ErZVw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_09uEGnDtJegPyZ-FY%2BUeCzDs_N1_%2BPsCYxCHu7_ErZVw%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_%2BPsCYxCHu7\_ErZVw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_09uEGnDtJegPyZ-FY%2BUeCzDs_N1_%2BPsCYxCHu7_ErZVw%40mail.gmail.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/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr)  
> [https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr?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/CAHXA0\_1cOrR%3D\_bndAjg-5CmL8q1AdJESCpj5NPtqxYeXUTscDw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_1cOrR%3D_bndAjg-5CmL8q1AdJESCpj5NPtqxYeXUTscDw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Paresh\_Behede](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paresh_behede/32/937_2.png) [@Paresh\_Behede](https://discuss.elastic.co/u/Paresh_Behede)\
**Post date:** [January 9, 2015, 7:25am UTC](https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532/5 "2015-01-09T07:25:38Z")

</div>

Thank you so much Rodu...solution worked for me...

Regards,  
Paresh B.

On Thursday, 8 January 2015 21:11:47 UTC+5:30, Radu Gheorghe wrote:

> Thanks, David! I had no idea it works until... about one hour ago 🙂
> 
> --  
> Performance Monitoring \* Log Analytics \* Search Analytics  
> Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)
> 
> On Thu, Jan 8, 2015 at 4:01 PM, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr)  
> \<javascript:\>\> wrote:
> 
> > Very nice Radu. I love this trick. 🙂
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> > [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > 
> > Le 8 janv. 2015 à 14:43, Radu Gheorghe \<[radu.g...@sematext.com](mailto:radu.g...@sematext.com)  
> > \<javascript:\>\> a écrit :
> > 
> > Hi Paresh,
> > 
> > If you want to sort on the field, I think it has to be the same type. So  
> > if you make everything a double, it should work for all numeric fields. To  
> > do that, you can use dynamic templates  
> > [http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#\_dynamic\_templates](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#_dynamic_templates).  
> > For example if you have this:
> > 
> > "mappings" : {  
> > "_default_" : {  
> > "dynamic\_templates" : [ {  
> > "long\_to\_float" : {  
> > "match" : "\*",  
> > "match\_mapping\_type" : "long",  
> > "mapping" : {  
> > "type" : "float"  
> > }  
> > }  
> > } ]  
> > }  
> > }
> > 
> > And add a new field with value=32, the field would be mapped as float  
> > instead of long.
> > 
> > ## Best regards, Radu
> > 
> > Performance Monitoring \* Log Analytics \* Search Analytics  
> > Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)
> > 
> > On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede \<[pares...@gmail.com](mailto:pares...@gmail.com)  
> > \<javascript:\>\> wrote:
> > 
> > > Hi,
> > > 
> > > I have requirement of storing document in Elasticsearch which will have  
> > > dynamic fields + those fields could have different data types values...
> > > 
> > > For e.g.,  
> > > Document 1 could have age field with value = 32, so when I would insert  
> > > 1st document in ES my index mapping will get created and age will be mapped  
> > > to Integer/Long
> > > 
> > > Now if I get age = 32.5 in another document ES will throw me exception  
> > > of data type mismatch...
> > > 
> > > Can you suggest what can I do to handle such scenario?
> > > 
> > > As workaround we are creating different fields for different data types  
> > > like age.long / age.double but this also won't work if I have to do sorting  
> > > over age field...
> > > 
> > > Kindly suggest...
> > > 
> > > Thanks in advance,  
> > > Paresh Behede
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_%2BPsCYxCHu7\_ErZVw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_09uEGnDtJegPyZ-FY%2BUeCzDs_N1_%2BPsCYxCHu7_ErZVw%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_%2BPsCYxCHu7\_ErZVw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_09uEGnDtJegPyZ-FY%2BUeCzDs_N1_%2BPsCYxCHu7_ErZVw%40mail.gmail.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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr)  
> > [https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr?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/3f740c21-3a2f-4794-9ee1-fb0c4088b48e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3f740c21-3a2f-4794-9ee1-fb0c4088b48e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [January 9, 2015, 7:55am UTC](https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532/6 "2015-01-09T07:55:06Z")

</div>

Hi Paresh,

You're welcome. I'm this  
[http://stuffmysisterswilllike.files.wordpress.com/2012/07/victory-kid.jpg](http://stuffmysisterswilllike.files.wordpress.com/2012/07/victory-kid.jpg)  
glad I nailed it!

## Best regards, Radu

Performance Monitoring \* Log Analytics \* Search Analytics  
Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)

On Fri, Jan 9, 2015 at 9:25 AM, Paresh Behede [paresh2711@gmail.com](mailto:paresh2711@gmail.com) wrote:

> Thank you so much Rodu...solution worked for me...
> 
> Regards,  
> Paresh B.
> 
> On Thursday, 8 January 2015 21:11:47 UTC+5:30, Radu Gheorghe wrote:
> 
> > Thanks, David! I had no idea it works until... about one hour ago 🙂
> > 
> > --  
> > Performance Monitoring \* Log Analytics \* Search Analytics  
> > Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)
> > 
> > On Thu, Jan 8, 2015 at 4:01 PM, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > 
> > > Very nice Radu. I love this trick. 🙂
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> > > [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > 
> > > Le 8 janv. 2015 à 14:43, Radu Gheorghe [radu.g...@sematext.com](mailto:radu.g...@sematext.com) a écrit  
> > > :
> > > 
> > > Hi Paresh,
> > > 
> > > If you want to sort on the field, I think it has to be the same type. So  
> > > if you make everything a double, it should work for all numeric fields. To  
> > > do that, you can use dynamic templates  
> > > [http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#\_dynamic\_templates](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/mapping-root-object-type.html#_dynamic_templates).  
> > > For example if you have this:
> > > 
> > > "mappings" : {  
> > > "_default_" : {  
> > > "dynamic\_templates" : [ {  
> > > "long\_to\_float" : {  
> > > "match" : "\*",  
> > > "match\_mapping\_type" : "long",  
> > > "mapping" : {  
> > > "type" : "float"  
> > > }  
> > > }  
> > > } ]  
> > > }  
> > > }
> > > 
> > > And add a new field with value=32, the field would be mapped as float  
> > > instead of long.
> > > 
> > > ## Best regards, Radu
> > > 
> > > Performance Monitoring \* Log Analytics \* Search Analytics  
> > > Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)
> > > 
> > > On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede [pares...@gmail.com](mailto:pares...@gmail.com)  
> > > wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I have requirement of storing document in Elasticsearch which will  
> > > > have dynamic fields + those fields could have different data types values...
> > > > 
> > > > For e.g.,  
> > > > Document 1 could have age field with value = 32, so when I would insert  
> > > > 1st document in ES my index mapping will get created and age will be mapped  
> > > > to Integer/Long
> > > > 
> > > > Now if I get age = 32.5 in another document ES will throw me exception  
> > > > of data type mismatch...
> > > > 
> > > > Can you suggest what can I do to handle such scenario?
> > > > 
> > > > As workaround we are creating different fields for different data types  
> > > > like age.long / age.double but this also won't work if I have to do sorting  
> > > > over age field...
> > > > 
> > > > Kindly suggest...
> > > > 
> > > > Thanks in advance,  
> > > > Paresh Behede
> > > > 
> > > > --  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_  
> > > %2BPsCYxCHu7\_ErZVw%[40mail.gmail.com](http://40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAHXA0\_09uEGnDtJegPyZ-FY%2BUeCzDs\_N1\_%2BPsCYxCHu7\_ErZVw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_09uEGnDtJegPyZ-FY%2BUeCzDs_N1_%2BPsCYxCHu7_ErZVw%40mail.gmail.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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%[40pilato.fr](http://40pilato.fr)  
> > > [https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr?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/3f740c21-3a2f-4794-9ee1-fb0c4088b48e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3f740c21-3a2f-4794-9ee1-fb0c4088b48e%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/3f740c21-3a2f-4794-9ee1-fb0c4088b48e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3f740c21-3a2f-4794-9ee1-fb0c4088b48e%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/CAHXA0\_0-n4eL5H\_HSJ4\_SjMO1e80GCv\_7oWr2Btv6FiM%2BH\_Lag%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_0-n4eL5H_HSJ4_SjMO1e80GCv_7oWr2Btv6FiM%2BH_Lag%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:39am UTC](https://discuss.elastic.co/t/how-can-i-store-2-different-data-types-in-same-field-of-2-different-document/21532/7 "2017-07-06T00:39:55Z")

</div>


