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

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ec663bd5-cf3b-4a3f-8828-03c4c53d3837%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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.
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/

On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede paresh2711@gmail.com wrote:

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.
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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
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.
For more options, visit https://groups.google.com/d/optout.

Very nice Radu. I love this trick. :slight_smile:

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr https://twitter.com/elasticsearchfr | @scrutmydocs https://twitter.com/scrutmydocs

Le 8 janv. 2015 à 14:43, Radu Gheorghe 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. 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 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?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?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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/E0768DFA-EF17-46F2-B488-5EC29A60E37D%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

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

--
Performance Monitoring * Log Analytics * Search Analytics
Solr & Elasticsearch Support * http://sematext.com/

On Thu, Jan 8, 2015 at 4:01 PM, David Pilato david@pilato.fr wrote:

Very nice Radu. I love this trick. :slight_smile:

--
David Pilato | Technical Advocate | Elasticsearch.com
http://Elasticsearch.com

@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr | @scrutmydocs
https://twitter.com/scrutmydocs

Le 8 janv. 2015 à 14:43, Radu Gheorghe 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.
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/

On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede paresh2711@gmail.com
wrote:

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.
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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
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?utm_medium=email&utm_source=footer
.

For more options, visit 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.
To view this discussion on the web visit 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.

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 :slight_smile:

--
Performance Monitoring * Log Analytics * Search Analytics
Solr & Elasticsearch Support * http://sematext.com/

On Thu, Jan 8, 2015 at 4:01 PM, David Pilato <da...@pilato.fr
<javascript:>> wrote:

Very nice Radu. I love this trick. :slight_smile:

--
David Pilato | Technical Advocate | Elasticsearch.com
http://Elasticsearch.com

@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr | @scrutmydocs
https://twitter.com/scrutmydocs

Le 8 janv. 2015 à 14:43, Radu Gheorghe <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.
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/

On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede <pares...@gmail.com
<javascript:>> wrote:

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 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?utm_medium=email&utm_source=footer
.
For more options, visit 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 <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?utm_medium=email&utm_source=footer
.
For more options, visit 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 <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?utm_medium=email&utm_source=footer
.

For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3f740c21-3a2f-4794-9ee1-fb0c4088b48e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Paresh,

You're welcome. I'm this
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/

On Fri, Jan 9, 2015 at 9:25 AM, Paresh Behede 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 :slight_smile:

--
Performance Monitoring * Log Analytics * Search Analytics
Solr & Elasticsearch Support * http://sematext.com/

On Thu, Jan 8, 2015 at 4:01 PM, David Pilato da...@pilato.fr wrote:

Very nice Radu. I love this trick. :slight_smile:

--
David Pilato | Technical Advocate | Elasticsearch.com
http://Elasticsearch.com

@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr | @scrutmydocs
https://twitter.com/scrutmydocs

Le 8 janv. 2015 à 14:43, Radu Gheorghe 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.
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/

On Thu, Jan 8, 2015 at 11:14 AM, Paresh Behede pares...@gmail.com
wrote:

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 elasticsearc...@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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
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?utm_medium=email&utm_source=footer
.

For more options, visit 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.
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?utm_medium=email&utm_source=footer
.

For more options, visit 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.
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.
For more options, visit https://groups.google.com/d/optout.