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

ClassCastException when sorting on incompatible fields #73146

Closed
fdartayre opened this issue May 17, 2021 · 1 comment · Fixed by #88399 · May be fixed by #74190
Closed

ClassCastException when sorting on incompatible fields #73146

fdartayre opened this issue May 17, 2021 · 1 comment · Fixed by #88399 · May be fixed by #74190
Assignees
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team

Comments

@fdartayre
Copy link
Contributor

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
}
@fdartayre fdartayre added >bug needs:triage Requires assignment of a team area label labels May 17, 2021
@romseygeek romseygeek added :Search/Search Search-related issues that do not fall into other categories and removed needs:triage Requires assignment of a team area label labels May 17, 2021
@elasticmachine elasticmachine added the Team:Search Meta label for search team label May 17, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@mayya-sharipova mayya-sharipova self-assigned this Jun 17, 2022
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this issue Jul 8, 2022
Currently when sorting on incompatible types, we get
class_cast_exception error. This patch improves
error message to explain that the probem is because
of incompatible sort types for the field across
different shards.

Closes elastic#73146
mayya-sharipova added a commit that referenced this issue Jul 11, 2022
Currently when sorting on incompatible types, we get
class_cast_exception error (code 500). This patch improves
the error to explain that the problem is because
of incompatible sort types for the field across
different shards and returns user error (code 400).

Closes #73146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team
Projects
None yet
4 participants