# Internally converting longs to ints?

**URL:** <https://discuss.elastic.co/t/internally-converting-longs-to-ints/21646>\
**Category:** Elasticsearch\
**Created:** [January 14, 2015, 7:41pm UTC](https://discuss.elastic.co/t/internally-converting-longs-to-ints/21646 "2015-01-14T19:41:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bparkison](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@bparkison](https://discuss.elastic.co/u/bparkison)\
**Post date:** [January 14, 2015, 7:41pm UTC](https://discuss.elastic.co/t/internally-converting-longs-to-ints/21646/1 "2015-01-14T19:41:48Z")

</div>

I've noticed that if specify a field in ElasticSearch as a "long", when I  
read the value back out via Java, sometimes the value is a Long, and  
sometimes it is an Integer. It appears that ElasticSearch is internally  
electing to store my long as an int (it's a small number), and when I read  
it back out, my original type specification is not being honored. Is this  
accurate? If so, do we have to worry about other types being downsized? I  
think I've seen it with dates, too. Anything else?

To be a little more concrete, let's say I have a mapping like:

{  
"testMapping" : {  
"properties" : {  
"fam0" : {  
"type" : "nested",  
"properties" : {  
"field1" : {"type" : "long" },  
}  
}  
}  
}  
}

Then, in Java, I have code that looks like:

{  
...  
Map\<String, Object\> esFamily;  
long value = (Long)esFamily.get(columnName);  
...  
}

With small values for field1, this gets a ClassCastException (can't cast  
Integer to Long). However, if I put big numbers into field1, it works fine.

Thanks,

Brian

--  
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/c301bcaf-ddb5-4287-95d9-a5f72278f928%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c301bcaf-ddb5-4287-95d9-a5f72278f928%40googlegroups.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:38am UTC](https://discuss.elastic.co/t/internally-converting-longs-to-ints/21646/2 "2017-07-06T00:38:54Z")

</div>


