Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float with no decimals are automatically converted to int #497

Closed
anthony-moyart opened this issue Dec 2, 2015 · 2 comments
Closed

Float with no decimals are automatically converted to int #497

anthony-moyart opened this issue Dec 2, 2015 · 2 comments

Comments

@anthony-moyart
Copy link

Hi,

I'm currently facing a tricky problem.
Some of my models have a GeoPoint, which represents coordinates (lat & lon) in two different float fields. For ElasticSearch to process these fields as I need it to, they need to have a float value, in any given circumstances.

The problem is, I default those coordinates to 0 (easy value to test throughout the codebase), and even when I force the (float) cast, and the type annotation is float too, the serializer ignores the decimal part if there is none (42.0 will result in 42), which is considered as an integer, and ElasticSearch doesn't seem to appreciate this kind of things...

@OeRnY
Copy link

OeRnY commented Jan 19, 2016

The interesting question is: "How is your elasticsearch set up?". I've tried to replicate this behaviour, yet my elasticsearch is able to store the number 42 into a floating number field without any problems.

@anthony-moyart
Copy link
Author

Sorry I solved the problem without updating this issue...

As is turns out, my index mapping was not complete, so when I tried to index my documents, some of them had "round" floats in the buggy field, and some others had floats with decimals. So, when the first document indexed by ES had a "round" float, it was rendered as an int by the serializer, which caused ES to map this field as an integer (causing bugs when actual floats where to be indexed).

I solved it by updating the mapping to explicitly set it as a float is ES, and it now works like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants