# ClassCastException when using Java API

**URL:** <https://discuss.elastic.co/t/classcastexception-when-using-java-api/22242>\
**Category:** Elasticsearch\
**Created:** [February 18, 2015, 3:29pm UTC](https://discuss.elastic.co/t/classcastexception-when-using-java-api/22242 "2015-02-18T15:29:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Molter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_molter/32/871_2.png) [@Tim\_Molter](https://discuss.elastic.co/u/Tim_Molter)\
**Post date:** [February 18, 2015, 3:29pm UTC](https://discuss.elastic.co/t/classcastexception-when-using-java-api/22242/1 "2015-02-18T15:29:25Z")

</div>

Hi,

I use the 'mapping' to get my datasources mapping.

transportClient.admin().indices().getMappings(new GetMappingsRequest().  
indices("myIndex")).get();

I then use what the mapping says to cast fields in returned documents. For  
one of the fields, the mapping says it's a long, but when I cast it I get:

! java.lang.ClassCastException: java.lang.Integer cannot be cast to java.  
lang.Long

when using the `getSource()` method, which returns a \<String, Object\> map.

long ts = (long) searchHit.getSource().get("ts");

Is this a bug in ES? It says it's a long, but the underlying Object in the  
map value is apparently an Integer!

--  
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/ec406cd1-2052-4b46-90ff-189267ff9832%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec406cd1-2052-4b46-90ff-189267ff9832%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tim\_Molter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_molter/32/871_2.png) [@Tim\_Molter](https://discuss.elastic.co/u/Tim_Molter)\
**Post date:** [February 25, 2015, 6:08pm UTC](https://discuss.elastic.co/t/classcastexception-when-using-java-api/22242/2 "2015-02-25T18:08:20Z")

</div>

Anyone, any ideas?

--  
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/0bdff454-a024-4629-b871-e7bc480f9bd8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0bdff454-a024-4629-b871-e7bc480f9bd8%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:30am UTC](https://discuss.elastic.co/t/classcastexception-when-using-java-api/22242/3 "2017-07-06T00:30:08Z")

</div>


