Uncertain field types when extracting fields from getSource() (java api)

You would need to keep track of the mapping yourself. As you noticed,
Elasticsearch returns Objects in the API. Someone attempted to build a
mapping framework around Elasticsearch, but it appears to have been
abandoned:

You can follow the same approach, try looking at that code. I bypassed
dynamic mapping and built an extraction library that deals with a ton of
ugly instanceof checks and cast the object to the appropriate type.

Cheers,

Ivan

On Tue, Jan 22, 2013 at 11:13 AM, Burak Emre Kabakcı
emrekabakci@gmail.comwrote:

Thanks for your reply. As far as I understand Elasticsearch uses Jackson
library. As you know getSource() returns Map<String, Object> and we don't
have any idea about real types of those Objects. We need to cast it to the
type we want to use with try / catch exceptions, it's not efficient and
proper way to do it. It would be great if it
returns org.codehaus.jackson.JsonNode. It provides asDouble(), asFloat()
etc. so it would be easy to extract fields from it.

On Tuesday, January 22, 2013 8:35:45 PM UTC+2, Igor Motov wrote:

When you are calling getSource(), you are getting the source that you
supplied during indexing. So, when you are trying to extract a field from
it, you are extracting this field from JSON object and Elasticsearch
mapping doesn't play any role in this process.

On Monday, January 21, 2013 9:03:16 AM UTC-5, Mo wrote:

I've seen this happen a couple of times.. specially when parsing geo
coords.

On Sunday, January 20, 2013 11:43:43 PM UTC+4, Burak Emre Kabakcı wrote:

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 orjava.**
lang.Integer. I encountered same problem for short type and it is
returned as java.lang.Integer Is it a bug or am I missing something?

--

--