Skip to content

Floating value with 17 decimal points return as 0 in query #4687

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

Closed
leelcs opened this issue May 1, 2020 · 2 comments
Closed

Floating value with 17 decimal points return as 0 in query #4687

leelcs opened this issue May 1, 2020 · 2 comments

Comments

@leelcs
Copy link

leelcs commented May 1, 2020

NEST/Elasticsearch.Net version:
NEST 7.6.1
NEST.JsonNetSerializer : 7.6.1
Elasticsearch version: 7.3.1

Description of the problem including expected versus actual behavior:
I have a document with _source as below: where the field: float-test is float data type

_source": {
"float-test": 0.25881904510252074,
"keyID": "93bdb772e5d84732bb7f877cae0210a6"
"version": "1.0"
}

From the Search result, the value of "float-test" become 0 as it rounded and lost precision, as below:
var result = client.Search(s => s
.Index(index)
.Size(1000)
.QueryOnQueryString("keyID:93bdb772e5d84732bb7f877cae0210a6")
);

QuickWatch-200430 095945

Expected behavior
How could i retain the exact value (0.25881904510252074) when read out from search result? Im using dynamic object for Index and Search.

@leelcs leelcs added the Bug label May 1, 2020
@russcam
Copy link
Contributor

russcam commented May 1, 2020

Hi @leelcs, this bug has been fixed in #4655 and will be in the next 7.x release, which we expect to put out in the very near future.

If it's a show stopper currently, you could reference a canary nuget package from our CI nuget feed which has the fix in. I just tested with version 7.6.0-ci20200430T143815 in Linqpad

void Main()
{
	var client = new ElasticClient(new ConnectionSettings(new InMemoryConnection()));
	
	var source = @"{
		""float-test"": 0.25881904510252074,
		""keyID"": ""93bdb772e5d84732bb7f877cae0210a6"",
		""version"": ""1.0""
		}
	";
	using var stream = new MemoryStream(Encoding.UTF8.GetBytes(source));

	var d = client.SourceSerializer.Deserialize<dynamic>(stream);
	
	((double)d["float-test"]).Dump();
}

which prints 0.25881904510252074.

Alternatively, if you were to define a type to deserialize _source into, where "float-test" is a double property type, that would also work without needing to reference a canary package. A POCO would look something like

public class MyDocument
{
    [DataMember(Name = "float-test")]
    public double FloatTest { get; set; }

    [DataMember(Name = "keyID")]
    public string KeyId { get; set; }

    [DataMember(Name = "version")]
    public string Version { get; set; }
}

I'm going to close this issue as it's already fixed. Thank you for raising!

@russcam russcam closed this as completed May 1, 2020
@leelcs
Copy link
Author

leelcs commented May 2, 2020

thanks @russcam for your immediate response! the copy in canary package fixed the issue.
Meanwhile, i will wait for the official next release. Thank you.

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