quickwit-oss/quickwit · error

Sort by more than 2 fields is not supported yet.

Error message

Sort by more than 2 fields is not supported yet.

What it means

The search collector's sort-building code supports sorting by at most two fields (SortByPair with a first and optional second component). When a query supplies a sort spec with three or more fields, the builder panics with this message instead of returning a user-facing error. It is a known limitation of the collector, not a malformed-request error.

Source

Thrown at quickwit/quickwit-search/src/collector.rs:1031

        SortByComponent::DocId {
            order: SortOrder::Desc,
        }
        .into()
    } else if num_sort_fields == 1 {
        let sort_field = &search_request.sort_fields[0];
        let order = SortOrder::try_from(sort_field.sort_order).unwrap_or(SortOrder::Desc);
        to_sort_by_component(&sort_field.field_name, order).into()
    } else if num_sort_fields == 2 {
        let sort_field1 = &search_request.sort_fields[0];
        let order1 = SortOrder::try_from(sort_field1.sort_order).unwrap_or(SortOrder::Desc);
        let sort_field2 = &search_request.sort_fields[1];
        let order2 = SortOrder::try_from(sort_field2.sort_order).unwrap_or(SortOrder::Desc);
        SortByPair {
            first: to_sort_by_component(&sort_field1.field_name, order1),
            second: Some(to_sort_by_component(&sort_field2.field_name, order2)),
        }
    } else {
        panic!("Sort by more than 2 fields is not supported yet.")
    }
}

/// Builds the QuickwitCollector, in function of the information that was requested by the user.
pub(crate) fn make_collector_for_split(
    split_id: SplitId,
    search_request: &SearchRequest,
    agg_context_params: AggContextParams,
) -> crate::Result<QuickwitCollector> {
    let aggregation = match &search_request.aggregation_request {
        Some(aggregation) => Some(serde_json::from_str(aggregation)?),
        None => None,
    };
    let sort_by = sort_by_from_request(search_request);
    Ok(QuickwitCollector {
        split_id,
        start_offset: search_request.start_offset as usize,
        max_hits: search_request.max_hits as usize,

View on GitHub (pinned to a39730c5cd)

Solutions

  1. Reduce the query's sort list to at most 2 fields.
  2. Return a proper InvalidQuery/validation error from the query parser instead of panicking, so users get a 4xx response.
  3. Extend the collector to a Vec<SortBy> if multi-field sorting is genuinely needed.

Example fix

// before
} else {
    panic!("Sort by more than 2 fields is not supported yet.")
}
// after
} else if sort_fields.len() > 2 {
    return Err(anyhow!("Sort by more than 2 fields is not supported yet."));
}
Defensive patterns

Strategy: validation

Validate before calling

if sort_fields.len() > 2 {
    return Err(invalid_query("Sort by more than 2 fields is not supported yet."));
}

Try / catch

// client-side: keep sort arrays to <=2 fields; server-side: return 400 via query validation, not panic.

Prevention

When it happens

Trigger: Issuing a search request (REST or ES-compat endpoint) whose `sort` array contains 3+ fields, reaching the else branch after sort_field1/sort_field2 handling.

Common situations: Porting Elasticsearch queries that sort on many fields; dashboards auto-generating multi-field sorts; users chaining tie-breaker sort keys.

Related errors


AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08). Data as JSON: /api/errors/bd338fdce72046ca. Report an issue: GitHub.