Uncertain field types when extracting fields from org.elasticsearch.search.SearchHit.getSource()

I'm trying to extract fields from
org.elasticsearch.search.SearchHit.getSource() but I'm having difficulties
of determining types of fields. For example I have a field named rank defined
as long with _mapping and when I extract it from Map<String, Object> I
couldn't be able to cast it Long because it returns as java.lang.Double or
java.lang.Integer. I encountered same problem for short type and it returns
as java.lang.Integer

--