quickwit-oss/tantivy · error

expected type string, which is always sortable

Error message

expected type string, which is always sortable

What it means

Fires when sorting final terms-agg buckets by key (OrderTarget::Key). Bucket keys are OwnedValue; the comparator uses partial_cmp and expects the key type to be string, which implements a total order, so the comparison never returns None. The panic indicates a bucket key of a non-string OwnedValue variant (e.g. numeric) reached a string-keyed terms aggregation, so the invariant 'string keys are always comparable' was violated.

Source

Thrown at src/aggregation/intermediate_agg_result.rs:954

                    key: key.into(),
                    doc_count: entry.doc_count,
                    sub_aggregation: entry
                        .sub_aggregation
                        .into_final_result_internal(sub_aggregation_req, limits)?,
                })
            })
            .collect::<crate::Result<_>>()?;

        let order = req.order.order;
        match req.order.target {
            OrderTarget::Key => {
                buckets.sort_by(|left, right| {
                    if req.order.order == Order::Asc {
                        left.key.partial_cmp(&right.key)
                    } else {
                        right.key.partial_cmp(&left.key)
                    }
                    .expect("expected type string, which is always sortable")
                });
            }
            OrderTarget::Count => {
                if req.order.order == Order::Desc {
                    buckets.sort_unstable_by_key(|bucket| std::cmp::Reverse(bucket.doc_count()));
                } else {
                    buckets.sort_unstable_by_key(|bucket| bucket.doc_count());
                }
            }
            OrderTarget::SubAggregation(name) => {
                let (agg_name, agg_property) = get_agg_name_and_property(&name);
                let mut buckets_with_val = buckets
                    .into_iter()
                    .map(|bucket| {
                        let val = bucket
                            .sub_aggregation
                            .get_value_from_aggregation(agg_name, agg_property)?
                            .unwrap_or(f64::MIN);

View on GitHub (pinned to b5d8deb80c)

Solutions

  1. Verify the terms aggregation request declares a string key type matching the indexed field
  2. Confirm intermediate key conversion produced OwnedValue::Str for string-keyed buckets
  3. If keys can be heterogeneous, replace the expect with an ordering that handles all OwnedValue variants
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/aggregation/intermediate_agg_result.rs:954 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of quickwit-oss/tantivy@b5d8deb80c (2026-09-05). Data as JSON: /api/errors/fa12042f977f4b63. Report an issue: GitHub.