Coerce attribute ineffective?


(Paul McMahon) #1

Hi,

I have a mapping with this :


              "mins" : {
                "type" : "byte",
				"coerce" : true,
				"index" : false 
}

But attempting to reindex into it I get:

"failed to parse [mins]","caused_by":{"type":"number_format_exception","reason":"For input string: \"0.0\""

Am I misunderstanding what 'coerce' is supposed to do?

Thanks

Paul


(Paul McMahon) #2

Actually, I've had a good mess about with 'coerce' and here is how it is behaving in 5.5:

indexing a value of "1" will succeed. Indexing a value of 1.1 will succeed. However, "1.0" (or "1.any digit") will fail.

You can see from the relevant code block that this is how it is coded to work (if the value is a string, coerce is apparently ignored altogether, it just tries to parse it)....
I'm not certain that is right, so I have opened this issue to suss it out :slight_smile:


(Zachary Tong) #3

We were just chatting about this internally and I was about to open an issue as well :slight_smile:

The behavior is a bit surprising (for me too). The behavior is basically what you described:

  • Floating numerics are truncated
  • Integral strings are converted via string parsing
  • Floating strings fail, because the integral string parsing bit doesn't know how to deal with them and we don't do anything to truncate the .xxx portion (or cast to double first and check to see if integral like we do in the numeric portion)

I think it should be fixed, and is fixable. :slight_smile:


(Paul McMahon) #4

Cool bananas, thanks Zachary... Agreed it looks pretty fixable; I'm happy to volunteer my assistance, though I currently have no dev env standing up with the appropriate tooling or anything :slight_smile:


(system) #5

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