Skip to content

Out of range query against field of long type gets clipped #27052

@mhko

Description

@mhko

We are running ES v5.6.3. When issuing a search query against a field of long type, we noticed that values are clipped to LONG_MAX/MIN when the value is out of range for the long type.

To reproduce

"docs": {
    "properties": {
        "Id": {
            "type": "keyword"
        },
        "long": {
            "type": "long"
        },
   }
}
  1. Index a document with Long.MAX_VALUE (9223372036854775807).

  2. Issue a search against the field "long" with a out-of-range values

_search/?q=long:9223372036854775808
_search/?q=long:9223372036854775809

returns the document with Long.MAX_VALUE (9223372036854775807) indexed above.

In ES1, such query throws a NumberFormatException. We believe ES6 would throw as well, looking at the code.

We think dd37cd14a4 is the responsible commit, line 731 of NumberFieldMapper.java.

+                try { 
+                    return Long.parseLong(stringValue); 
+                } catch (NumberFormatException e) { 
+                    return (long) Double.parseDouble(stringValue);   <-------------- 731
+                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search/SearchSearch-related issues that do not fall into other categoriesdiscuss

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions