Skip to content

ClassCastException when sorting while mixing long and float fields #80658

@bczifra

Description

@bczifra

Elasticsearch version (bin/elasticsearch --version): 7.15.0

Description of the problem including expected versus actual behavior:
When sorting search results from two different indices, if a field is defined as a long in one index and a float in the other index, a ClassCastException is thrown rather then Elasticsearch coalescing both values to a "numeric" value and sorting them.

Steps to reproduce:

PUT long
{
  "mappings": {
    "properties": {
      "foo": {
        "type": "long"
      }
    }
  }
}

PUT float
{
  "mappings": {
    "properties": {
      "foo": {
        "type": "float"
      }
    }
  }
}

POST long/_doc/1
{
  "foo": "123"
}

POST float/_doc/1
{
  "foo": 1.23
}

POST long,float/_search
{ "sort": "foo" }

The last query returns:

{
  "error" : {
    "root_cause" : [ ],
    "type" : "search_phase_execution_exception",
    "reason" : "",
    "phase" : "fetch",
    "grouped" : true,
    "failed_shards" : [ ],
    "caused_by" : {
      "type" : "class_cast_exception",
      "reason" : "class java.lang.Float cannot be cast to class java.lang.Long (java.lang.Float and java.lang.Long are in module java.base of loader 'bootstrap')"
    }
  },
  "status" : 500
}

This is the case even if one of the documents has the field defined with a null value- as long as the mapping of the field differs, this exception is thrown.

Related:

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions