quickwit-oss/tantivy · error
unexpected aggregation, expected multi_terms aggregation
Error message
unexpected aggregation, expected multi_terms aggregation
What it means
Fires while converting intermediate bucket results into final aggregation results. The code pattern-matches on the variant of IntermediateBucketResult and then downcasts the request's inner agg enum to the matching request type; for the MultiTerms variant it expects req.agg to hold a multi_terms aggregation. If the intermediate result says MultiTerms but the original request was not a multi_terms aggregation, as_multi_terms() returns None and this panic fires, meaning the request and its intermediate results are out of sync (an internal invariant violation, e.g. wrong req passed to into_final_bucket_result).
Source
Thrown at src/aggregation/intermediate_agg_result.rs:721
let final_sub_aggregations = sub_aggregations
.into_final_result(req.sub_aggregation().clone(), limits.clone())?;
Ok(BucketResult::Filter(FilterBucketResult {
doc_count,
sub_aggregations: final_sub_aggregations,
}))
}
IntermediateBucketResult::Composite { buckets } => {
let composite_req = req
.agg
.as_composite()
.expect("unexpected aggregation, expected composite aggregation");
buckets.into_final_result(composite_req, req.sub_aggregation(), limits)
}
IntermediateBucketResult::MultiTerms { buckets } => {
let multi_terms_req = req
.agg
.as_multi_terms()
.expect("unexpected aggregation, expected multi_terms aggregation");
buckets.into_final_result(multi_terms_req, req.sub_aggregation(), limits)
}
}
}
pub(crate) fn prune_intermediate_results(
&mut self,
req: &Aggregation,
mode: PruneMode,
) -> crate::Result<()> {
match self {
IntermediateBucketResult::Terms { buckets } => {
let terms_req = req
.agg
.as_term()
.expect("unexpected aggregation, expected term aggregation");
buckets.prune_intermediate_results(terms_req, req.sub_aggregation(), mode)
}View on GitHub (pinned to b5d8deb80c)
Solutions
- Ensure into_final_bucket_result is called with the Aggregation request that actually produced this intermediate bucket result
- Check that request deserialization and execution use the same aggregation type enum variant
- Audit any custom code that constructs IntermediateBucketResult::MultiTerms to confirm the paired request is AggregationVariants::MultiTerms
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/aggregation/intermediate_agg_result.rs:721 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/c067749fdd543b86.
Report an issue: GitHub.