Float and integer fields' datatypes


(Vladimir) #1

https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html and
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html point that the following numeric data types are supported :

  • long
  • integer
  • short
  • byte
  • double
  • float
  • half_float
  • scaled_float

However this doc page, https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html, says:

Each field has a data type which can be:
a simple type like text, keyword, date, long, double, boolean or ip.
....

So does it mean fields cannot be integer and float and should be instead long and double accordingly ?


(Alexander Reelsen) #2

No, you can configure integers or floats or doubles or longs. The second listing was just an example. The first list is the definitive one.


(Vladimir) #3

Hi Alexander ,
Thanks
How to use null_value in mapping for all numeric and text type if we rely on dynamic mapping?
Can you give an example?


(Vladimir) #4

When I place integer and float into dynamic template I got warning above acknowledgement in Kibana console:

#! Deprecation: match_mapping_type [integer] is invalid and will be ignored: No field type matched on [integer], possible values are [object, string, long, double, boolean, date, binary]
#! Deprecation: match_mapping_type [float] is invalid and will be ignored: No field type matched on [float], possible values are [object, string, long, double, boolean, date, binary]

So I need to understand really if integer and float are supported and how to map them in dynamic template


(Vladimir) #5

I found in documentation a comment about match-mapping-type, see https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#match-mapping-type

The match_mapping_type matches on the datatype detected by dynamic field mapping, in other words, the datatype that Elasticsearch thinks the field should have. Only the following datatypes can be automatically detected: boolean, date, double, long, object, string

Recommendation is to use "match_mapping_type": "long" for integer and "match_mapping_type": "double" for float data types.

I made correction to mapping. There is not more any Warning messages at index creation time. The mapping is created according to data type.
However at runtime jave RestClient get Integer instance for long and integer datatype , and Double instance for float and doable datatype . The reason of that seems to me lays in Jackson2 object mapping. When Jackson2 needs to map float or long it does not distinguish the number received by RestClient in Response. The question is how serialized and deserialized Float and Long value using Jackson2 to aviid default Jackson behavior which coverts objects to Integer and Double


(system) #6

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.