Skip to content

ClassCastException when sorting on incompatible fields #73146

@fdartayre

Description

@fdartayre

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

Description of the problem including expected versus actual behavior:
Elasticsearch returns a ClassCastException when trying to sort on incompatible fields across indexes. Discussing this with @romseygeek, we should be returning a specific error instead.

Steps to reproduce:

PUT index_1
{
  "mappings": {
    "properties": {
      "date": {
        "type": "keyword"
      }
    }
  }
}

PUT index_2
{
  "mappings": {
    "properties": {
      "date": {
        "type": "date"
      }
    }
  }
}

POST index_1/_doc
{ "date": "2021-05-17" }

POST index_2/_doc
{ "date": "2021-05-17" }

GET index_1,index_2/_search
{ "sort": "date" }

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.Long cannot be cast to class org.apache.lucene.util.BytesRef (java.lang.Long is in module java.base of loader 'bootstrap'; org.apache.lucene.util.BytesRef is in unnamed module of loader 'app')"
    }
  },
  "status" : 500
}

Metadata

Metadata

Labels

:Search/SearchSearch-related issues that do not fall into other categories>bugTeam:SearchMeta label for search team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions