Skip to content

Handling of 0.0 and -0.0 in range (lt and gt) queries has changed from 2.4.3 > 5.1.1 #22167

@hithran

Description

@hithran

Elasticsearch version: 5.1.1

JVM version: 1.8.0_111

OS version: CentOS 6.8

Description of the problem including expected versus actual behavior:
When there are 2 documents, 1 with value 0.0 and the other with value -0.0, ES 5.1.1 no longer returns the documents when a range query is execute with either gt -0.0 or lt 0.0. Where as ES 2.4.3 would return the document with value 0.0 for gt -0.0 and return the document with value -0.0 for lt 0.0.

lte and gte do work correctly, lte 0.0 and gte -0.0 return both documents

Steps to reproduce:

  1. curl -XPUT localhost:9200/double-test?pretty -d '{ "mappings": { "double-values": { "properties": { "number": { "type": "double" }}}}}'
{
  "acknowledged" : true,
  "shards_acknowledged" : true
}
  1. curl -XPOST localhost:9200/double-testing/double-values?pretty -d '{ "number": 0.0 }'
{
  "_index" : "double-testing",
  "_type" : "double-values",
  "_id" : "AVj9f_B77DB0gWTRwMi9",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "created" : true
}
  1. curl -XPOST localhost:9200/double-testing/double-values?pretty -d '{ "number": -0.0 }'
{
  "_index" : "double-testing",
  "_type" : "double-values",
  "_id" : "AVj9f_087DB0gWTRwMi-",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "created" : true
}
  1. curl localhost:9200/double-testing/double-values/_search?pretty
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "double-testing",
        "_type" : "double-values",
        "_id" : "AVj9f_B77DB0gWTRwMi9",
        "_score" : 1.0,
        "_source" : {
          "number" : -0.0
        }
      },
      {
        "_index" : "double-testing",
        "_type" : "double-values",
        "_id" : "AVj9f_087DB0gWTRwMi-",
        "_score" : 1.0,
        "_source" : {
          "number" : 0.0
        }
      }
    ]
  }
}
  1. curl localhost:9200/double-testing/double-values/_search?pretty -d '{ "query": { "range": { "number": { "lt": 0.0 }}}}'
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}
  1. curl localhost:9200/double-testing/double-values/_search?pretty -d '{ "query": { "range": { "number": { "lte": 0.0 }}}}'
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "double-testing",
        "_type" : "double-values",
        "_id" : "AVj9f_B77DB0gWTRwMi9",
        "_score" : 1.0,
        "_source" : {
          "number" : -0.0
        }
      },
      {
        "_index" : "double-testing",
        "_type" : "double-values",
        "_id" : "AVj9f_087DB0gWTRwMi-",
        "_score" : 1.0,
        "_source" : {
          "number" : 0.0
        }
      }
    ]
  }
}
  1. curl localhost:9200/double-testing/double-values/_search?pretty -d '{ "query": { "range": { "number": { "gt": -0.0 }}}}'
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}
  1. curl localhost:9200/double-testing/double-values/_search?pretty -d '{ "query": { "range": { "number": { "gte": -0.0 }}}}'
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "double-testing",
        "_type" : "double-values",
        "_id" : "AVj9f_B77DB0gWTRwMi9",
        "_score" : 1.0,
        "_source" : {
          "number" : -0.0
        }
      },
      {
        "_index" : "double-testing",
        "_type" : "double-values",
        "_id" : "AVj9f_087DB0gWTRwMi-",
        "_score" : 1.0,
        "_source" : {
          "number" : 0.0
        }
      }
    ]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search/SearchSearch-related issues that do not fall into other categories>bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions