quickwit-oss/tantivy · error

TermMissingAgg collector, but no missing found in agg req

Error message

TermMissingAgg collector, but no missing found in agg req

What it means

A panic in `add_intermediate_aggregation_result` of TermMissingAgg: `agg_data.get_missing_term_req_data(...)` returned request data whose `.missing` field is `None`, but the collector only exists when a `missing` value was configured on the terms aggregation. This is an internal consistency violation between the aggregation request parsing and the collector construction — the intermediate result and the aggregation definition disagree.

Source

Thrown at src/aggregation/bucket/term_missing_agg.rs:94

            bucket_id_provider,
        })
    }
}

impl SegmentAggregationCollector for TermMissingAgg {
    fn add_intermediate_aggregation_result(
        &mut self,
        agg_data: &AggregationsSegmentCtx,
        results: &mut IntermediateAggregationResults,
        parent_bucket_id: BucketId,
    ) -> crate::Result<()> {
        self.prepare_max_bucket(parent_bucket_id, agg_data)?;
        let req_data = agg_data.get_missing_term_req_data(self.accessor_idx);
        let term_agg = &req_data.req;
        let missing = term_agg
            .missing
            .as_ref()
            .expect("TermMissingAgg collector, but no missing found in agg req")
            .clone();
        let mut entries: FxHashMap<IntermediateKey, IntermediateTermBucketEntry> =
            Default::default();

        let missing_count = &self.missing_count_per_bucket[parent_bucket_id as usize];
        let mut missing_entry = IntermediateTermBucketEntry {
            doc_count: missing_count.missing_count as u64,
            sub_aggregation: Default::default(),
        };
        if let Some(sub_agg) = &mut self.sub_agg {
            let mut res = IntermediateAggregationResults::default();
            sub_agg
                .get_sub_agg_collector()
                .add_intermediate_aggregation_result(agg_data, &mut res, missing_count.bucket_id)?;
            missing_entry.sub_aggregation = res;
        }
        entries.insert(missing.into(), missing_entry);

View on GitHub (pinned to b5d8deb80c)

Solutions

  1. Check that every terms aggregation using the missing-term path actually sets a `missing` value in the request JSON.
  2. Ensure all nodes in a cluster run the same engine version so request/intermediate formats match.
  3. Inspect how the aggregation request is deserialized — a dropped `missing` field during parsing is the usual root cause.
  4. If you maintain the code, return a descriptive internal error instead of expecting, to aid debugging.

Example fix

// before
let missing = term_agg.missing.as_ref().expect("TermMissingAgg collector, but no missing found in agg req").clone();
// after
let missing = term_agg.missing.as_ref().cloned().ok_or_else(|| {
    crate::AggregationError::Internal("TermMissingAgg without missing in req".to_string())
})?;
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the terms agg request actually sets "missing" when relying on the missing-term path.
fn request_has_missing(req: &serde_json::Value) -> bool {
    req.get("aggs")
        .and_then(|a| a.get("my_terms"))
        .and_then(|t| t.get("terms"))
        .map(|t| t.get("missing").is_some())
        .unwrap_or(false)
}

Try / catch

let res = std::panic::catch_unwind(|| finalize_intermediate_aggs(...));
if res.is_err() {
    log::error("agg finalization panic: missing-term collector without missing in request");
    return internal_error_response();
}

Prevention

When it happens

Trigger: Calling `add_intermediate_aggregation_result` on a TermMissingAgg collector when the aggregation request carries `missing: None` — i.e. the request data was built without the `missing` parameter despite the missing-term collector being instantiated (typically a bug in request deserialization or collector wiring).

Common situations: A distributed search where intermediate aggregation results from one node/version are combined with request data built by another version; a bug in aggregation request parsing that drops the `missing` field; manually constructed intermediate agg results in tests/plugins.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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