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

[BUG] the aggregation result in float field type is inaccurate #14966

Open
kkewwei opened this issue Jul 24, 2024 · 4 comments
Open

[BUG] the aggregation result in float field type is inaccurate #14966

kkewwei opened this issue Jul 24, 2024 · 4 comments
Labels
bug Something isn't working Search:Aggregations

Comments

@kkewwei
Copy link
Contributor

kkewwei commented Jul 24, 2024

Describe the bug

When aggregating in float field type, the returned result may be not accurate, but the query result is accurate.
image

Related component

Search:Aggregations

To Reproduce

  1. create the index:
PUT test1
{
  "mappings" : {
    "properties" : {
      "float1":{
          "type":"float"
      }
    }
  }
}
  1. index
PUT test1/_doc/122
{
    "integer1":"2",
    "float1":0.000001,
    "short1":2
}
  1. aggs
POST test1/_search
{
    "aggs":{
        "aggs1":{
            "terms":{
                "field":"float1"
            }
        }
    }
}

Additional Details

Plugins
Please list all plugins currently enabled.

Screenshots
If applicable, add screenshots to help explain your problem.

Host/Environment (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@mgodwan
Copy link
Member

mgodwan commented Jul 25, 2024

This seems like a precision issue (32 vs 64 bits) to me.

Can be reproduced with:

 NumericUtils.sortableLongToDouble(NumericUtils.doubleToSortableLong(0.000001f)) // Returns 9.999999974752427E-7

If we use double for the initial value

 NumericUtils.sortableLongToDouble(NumericUtils.doubleToSortableLong(0.000001d)) // Returns  1.0E-6

@kkewwei Since the mapping type used here is float, the precision is lost when the value is actually parsed as a number and you get the nearest value representable as float and is used in bucket creation. The hit returned returns the source as it was ingested (i.e. the source content itself), and hence shows the provided value.

Using double in mappings should solve this

@kkewwei
Copy link
Contributor Author

kkewwei commented Jul 25, 2024

@mgodwan yes if it's a bug, I'm pleasure to solve it.

@getsaurabh02
Copy link
Member

@mgodwan let us know if this still needs to be fixed? we are assuming this is just a mapping issue based on the comment " mappings should solve this"

@kkewwei
Copy link
Contributor Author

kkewwei commented Aug 1, 2024

@mgodwan let us know if this still needs to be fixed? we are assuming this is just a mapping issue based on the comment " mappings should solve this"

I think we should fix it, as float field type is common, when it is used in aggregation, the bucket name of the aggregation response may be inaccurate, which is confusing to user. We can't force the user not to use float field type in aggregation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Search:Aggregations
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants