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 while mixing long and float fields #80658

Open
bczifra opened this issue Nov 11, 2021 · 5 comments
Open

ClassCastException when sorting while mixing long and float fields #80658

bczifra opened this issue Nov 11, 2021 · 5 comments
Assignees
Labels
>enhancement :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch

Comments

@bczifra
Copy link
Member

bczifra commented Nov 11, 2021

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:

@bczifra bczifra added >bug needs:triage Requires assignment of a team area label labels Nov 11, 2021
@cbuescher
Copy link
Member

@bczifra I think this is fully captured in #78699, would you mind if we close this issue as a duplicate?

@cbuescher
Copy link
Member

cbuescher commented Nov 11, 2021

Ah, I just see this ist long-float. Same area though, maybe we can add this to the other issue though.

@romseygeek romseygeek added the :Search/Search Search-related issues that do not fall into other categories label Nov 11, 2021
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Nov 11, 2021
@elasticmachine
Copy link
Collaborator

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

@romseygeek romseygeek removed Team:Search Meta label for search team needs:triage Requires assignment of a team area label labels Nov 11, 2021
@javanna javanna added the Team:Search Meta label for search team label Feb 2, 2022
@mayya-sharipova mayya-sharipova self-assigned this Jun 17, 2022
@benwtrent
Copy link
Member

I am relabeling this. Mixing types like this is a significant enhancement, as covered by multiple other issues:

#78699

#84799

I do think we should transparently allow "up-casting" to different sort types. So, float would be comparable to double and int comparable with double, etc.

@javanna javanna added :Search Relevance/Search Catch all for Search Relevance and removed :Search/Search Search-related issues that do not fall into other categories labels Jul 17, 2024
@elasticsearchmachine elasticsearchmachine added Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 17, 2024
@elasticsearchmachine
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch
Projects
None yet
Development

No branches or pull requests

8 participants