Skip to content

Sorting on incompatible field types in top_hits across shards returns 500 instead of 400 #141906

@astefan

Description

@astefan

Description

Issue similar (probably the same, but in a different sorting scenario - top_hits instead of root level sorting) with #127965.

my_store_inventory_float

{
  "mappings": {
    "properties": {
      "item_id": { "type": "keyword" },
      "product_name": { "type": "text" },
      "brand_id": { "type": "float" },  // brand_id is float in this index
      "price": { "type": "float" },
      "timestamp": { "type": "date" }
    }
  }
}
my_store_inventory_long

{
  "mappings": {
    "properties": {
      "item_id": { "type": "keyword" },
      "product_name": { "type": "text" },
      "brand_id": { "type": "long" },  // brand_id is long in this index
      "price": { "type": "float" },
      "timestamp": { "type": "date" }
    }
  }
}
{ "index": { "_id": "1", "_index":"my_store_inventory_float" } }
{ "item_id": "item_A1", "product_name": "Super Widget X", "brand_id": 101, "price": 10.99, "timestamp": "2025-05-01T10:00:00Z" }
{ "index": { "_id": "1", "_index":"my_store_inventory_long" } }
{ "item_id": "item_A2", "product_name": "Basic Widget", "brand_id": 101, "price": 8.99, "timestamp": "2025-05-02T11:00:00Z" }
{
 "query": {
    "match_all": {} 
  },
  "aggs": {
    "top_sales_hits": {
        "top_hits": {
        "sort": [
                { "brand_id": "asc" }, 
                { "price": "desc" }
        ],
        "size": 1
        }
    }
  }
}

results in

{
    "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
}

It should return 400x, just like the previous issue - #127965 - where the outcome is

        "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Can't sort on field [brand_id]; the field has incompatible sort types: [FLOAT] and [LONG] across shards!"
        }
    },
    "status": 400

Metadata

Metadata

Assignees

Labels

:Search Relevance/SearchCatch all for Search Relevance>bugTeam:Search RelevanceMeta label for the Search Relevance team in Elasticsearchpriority:highA label for assessing bug priority to be used by ES engineers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions