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

scaled_float has precision problem #27189

Closed
donvanf opened this issue Oct 31, 2017 · 2 comments · Fixed by #27207
Closed

scaled_float has precision problem #27189

donvanf opened this issue Oct 31, 2017 · 2 comments · Fixed by #27207
Labels
>bug help wanted adoptme :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@donvanf
Copy link

donvanf commented Oct 31, 2017

Describe the feature:

Elasticsearch version (bin/elasticsearch --version):
5.0.1, Build: 080bb47/2016-11-11T22:08:49.812Z

Plugins installed: []

JVM version (java -version):
1.8.0_131
OS version (uname -a if on a Unix-like system):
CentOS release 6.5
Description of the problem including expected versus actual behavior:
Results from inner_hits named "a" should be returned only if my_parent's key equal 3.
Steps to reproduce:

Please include a minimal but complete recreation of the problem, including
(e.g.) index creation, mappings, settings, query etc. The easier you make for
us to reproduce it, the more likely that somebody will take the time to look at it.

PUT test
{
  "mappings": {
    "type": {
      "properties": {
        "scaled_float_field": {
          "type": "scaled_float",
          "scaling_factor": 100
        }
      }
    }
  }
}
POST _bulk
{"update": {"_index": "test","_type": "type","_id": "1"}}
{"doc": {"scaled_float_field": 0.1},"doc_as_upsert": true}
POST test/_search
{
  "query": {
    "range": {
      "scaled_float_field": {
        "lt": 0.1
      }
    }
  }
}

result

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "test",
        "_type": "type",
        "_id": "1",
        "_score": 1,
        "_source": {
          "scaled_float_field": 0.1
        }
      }
    ]
  }
}

As Document mentions here, scaled_float is stored as long type. Why it also has precision problem?

@jpountz jpountz self-assigned this Oct 31, 2017
@jpountz
Copy link
Contributor

jpountz commented Oct 31, 2017

This is a bug indeed. Range queries are supposed to work as if the field was mapped as a double field that only contains rounded values.

@jpountz
Copy link
Contributor

jpountz commented Oct 31, 2017

Even though this is considered a bug, I'd like to point out that relying on equality on doubles may be a source of problems for other reasons, especially since 0.1 cannot be represented accurately as a double.

@jpountz jpountz added :Search Foundations/Mapping Index mappings, including merging and defining field types help wanted adoptme >bug labels Oct 31, 2017
@jpountz jpountz removed their assignment Oct 31, 2017
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this issue Nov 3, 2017
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this issue Nov 3, 2017
dakrone pushed a commit that referenced this issue Nov 3, 2017
*  #27189 Fixed rounding of bounds in scaled float comparison

*  #27189 more assertions from CR
dakrone pushed a commit that referenced this issue Nov 3, 2017
*  #27189 Fixed rounding of bounds in scaled float comparison

*  #27189 more assertions from CR
dakrone pushed a commit that referenced this issue Nov 3, 2017
*  #27189 Fixed rounding of bounds in scaled float comparison

*  #27189 more assertions from CR
martijnvg added a commit that referenced this issue Nov 4, 2017
* es/master:
  Fix snapshot getting stuck in INIT state (#27214)
  Add an example of dynamic field names (#27255)
  #26260 Allow ip_range to accept CIDR notation (#27192)
  #27189 Fixed rounding of bounds in scaled float comparison (#27207)
  Add support for Gradle 4.3 (#27249)
  Fixes QueryStringQueryBuilderTests
  build: Fix setting the incorrect bwc version in mixed cluster qa module
  [Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery BWC
  Adjust assertions for sequence numbers BWC tests
  Do not create directories if repository is readonly (#26909)
  [Test] Fix InternalStatsTests
  [Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery
  Uses norms for exists query if enabled (#27237)
  Reinstate recommendation for ≥ 3 master-eligible nodes. (#27204)
martijnvg added a commit that referenced this issue Nov 4, 2017
* 6.x:
  Add an example of dynamic field names (#27255)
  fixed checkstyle violation
  #26260 Allow ip_range to accept CIDR notation (#27192)
  #27189 Fixed rounding of bounds in scaled float comparison (#27207)
  [TEST] Fix failing exists query test
  test: Do not run old parent/child tests against a cluster with minimum version greater than 6.0.0
  Add support for Gradle 4.3 (#27249)
  Fixes QueryStringQueryBuilderTests
  build: Fix setting the incorrect bwc version in mixed cluster qa module
  fix compil after backport
  [Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery BWC
  Adjust assertions for sequence numbers BWC tests
  Do not create directories if repository is readonly (#26909)
  [Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery
  Uses norms for exists query if enabled (#27237)
  Reinstate recommendation for ≥ 3 master-eligible nodes. (#27204)
@javanna javanna added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug help wanted adoptme :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants