Deducing field type using elasticsearch Java API

Hi all,

In my project, I need to deduce the data type of some JSON tree liefs
based on their value and I want to use the same API/mechanism that
elasticsearch uses to do this.
At some point, when indexing documents, elasticsearch will need to do
this job, and I would like to use the same API/mechanism that
elasticsearch uses to avoid different type deduction.

Can anyone help?

Thanks in advance!

The logic is quite naive, Numeric Java types are mapped to the relevant
numeric types, and Dates are serialized using the default ISO string format.

On Mon, Nov 21, 2011 at 7:10 PM, vannya vannyas@gmail.com wrote:

Hi all,

In my project, I need to deduce the data type of some JSON tree liefs
based on their value and I want to use the same API/mechanism that
elasticsearch uses to do this.
At some point, when indexing documents, elasticsearch will need to do
this job, and I would like to use the same API/mechanism that
elasticsearch uses to avoid different type deduction.

Can anyone help?

Thanks in advance!

Although the logic is naive, is it available in some kind of API that can be used ?

I cannot take the chance of getting the wrong type deduction (or different from the one that elastic will do) and that's why I need to use the exact same code that elastic uses to do his own deduction.

Thanks,

If you are that concerned, then generate the json yourself (I recommend
jackson), you can always provide the document in a binary format. Here is
an example of the "types" supported:
https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java#L616
.

On Tue, Nov 22, 2011 at 5:40 PM, vannya vannyas@gmail.com wrote:

Although the logic is naive, is it available in some kind of API that can
be
used ?

I cannot take the chance of getting the wrong type deduction (or different
from the one that elastic will do) and that's why I need to use the exact
same code that elastic uses to do his own deduction.

Thanks,

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Deducing-field-type-using-elasticsearch-Java-API-tp3525339p3528065.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

Another less complicated way to ensure types is to specify the mapping
explicitly before indexing. This way you never end up with a wrongly
interpreted type by ES, and you know what to expect on the client
side.

Jérémie

On Fri, Nov 25, 2011 at 8:48 AM, Shay Banon kimchy@gmail.com wrote:

If you are that concerned, then generate the json yourself (I recommend
jackson), you can always provide the document in a binary format. Here is an
example of the "types"
supported: https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java#L616.

On Tue, Nov 22, 2011 at 5:40 PM, vannya vannyas@gmail.com wrote:

Although the logic is naive, is it available in some kind of API that can
be
used ?

I cannot take the chance of getting the wrong type deduction (or different
from the one that elastic will do) and that's why I need to use the exact
same code that elastic uses to do his own deduction.

Thanks,

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Deducing-field-type-using-elasticsearch-Java-API-tp3525339p3528065.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--
Jérémie 'ahFeel' BORDIER

Hi,

Jérémie, my data set is huge and I don't know it exactly it's fields,
so I don't know which fields to map... and even if I knew, it wouldn't
be easier! Thanks for your reply anyway.

Shay, thanks for tour reply.
My solution was achieved using JsonPrimitive type comparions
(isBoolean, isString and isNumber), which in the end, does the same
that your field API: compares a field class against the native Java
types. I belive my problem is solved now.

Thank you all,

On Nov 25, 8:04 am, Jérémie BORDIER jeremie.bord...@gmail.com wrote:

Another less complicated way to ensure types is to specify the mapping
explicitly before indexing. This way you never end up with a wrongly
interpreted type by ES, and you know what to expect on the client
side.

Jérémie

On Fri, Nov 25, 2011 at 8:48 AM, Shay Banon kim...@gmail.com wrote:

If you are that concerned, then generate the json yourself (I recommend
jackson), you can always provide the document in a binary format. Here is an
example of the "types"
supported: https://github.com/elasticsearch/elasticsearch/blob/master/modules/el....

On Tue, Nov 22, 2011 at 5:40 PM, vannya vann...@gmail.com wrote:

Although the logic is naive, is it available in some kind of API that can
be
used ?

I cannot take the chance of getting the wrong type deduction (or different
from the one that elastic will do) and that's why I need to use the exact
same code that elastic uses to do his own deduction.

Thanks,

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Deducing-field-type-u...
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--
Jérémie 'ahFeel' BORDIER