{"record":{"id":"3c169c08c3fa0c9e","repo":"quickwit-oss/quickwit","slug":"the-key-value-has-to-be-a-json-object","errorCode":null,"errorMessage":"the `{key}` value has to be a json object","messagePattern":"the `(.+?)` value has to be a json object","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-doc-mapper/src/doc_mapper/doc_mapper_impl.rs","lineNumber":421,"sourceCode":"    let mut values = if let Some(values) = doc.remove(key) {\n        values\n    } else {\n        return Ok(None);\n    };\n    if values.len() > 1 {\n        bail!(\n            \"invalid named document. there are more than 1 value associated to the `{key}` field\"\n        );\n    }\n    match values.pop() {\n        Some(TantivyValue::Object(dynamic_json_obj)) => Ok(Some(\n            dynamic_json_obj\n                .into_iter()\n                .map(|(key, val)| (key, tantivy_value_to_json(val)))\n                .collect(),\n        )),\n        Some(_) => {\n            bail!(\"the `{key}` value has to be a json object\");\n        }\n        None => Ok(None),\n    }\n}\n\nimpl DocMapper {\n    /// Returns the unique identifier of the doc mapping.\n    pub fn doc_mapping_uid(&self) -> DocMappingUid {\n        self.doc_mapping_uid\n    }\n\n    /// Validates a JSON object according to the doc mapper.\n    pub fn validate_json_obj(&self, json_obj: &BorrowedJsonMap) -> Result<(), DocParsingError> {\n        let is_strict = self.mode.mode_type() == ModeType::Strict;\n        let mut field_path = Vec::new();\n        self.field_mappings\n            .validate_from_json(json_obj, is_strict, &mut field_path)?;\n        if let Some(timestamp_field_path) = &self.timestamp_field_path {","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-doc-mapper/src/doc_mapper/doc_mapper_impl.rs#L403-L439","documentation":"extract_single_obj expects the single stored value under a key to be a tantivy JSON object (the representation of a dynamic/object field). If the value exists but is any other type (scalar, string, etc.), the function cannot turn it into the expected nested JSON object and bails. It is the sibling check to error 81 in the doc-to-json conversion path.","triggerScenarios":"Calling doc_to_json on a document where a key's single stored value is a non-object TantivyValue (e.g. Str, Str/number) while the caller path expected an object field.","commonSituations":"Retrieving stored docs for fields whose schema type changed between versions (object -> text); indexing a scalar into a field path later read as an object; viewing _source output for documents written before a mapping change.","solutions":["Align the field type in the index config with the data actually stored (if it's a scalar, read it as its real type, not as an object).","Re-index affected documents after fixing the mapping so stored values match the declared field type.","Check for schema migrations that changed a field from object/json to text without reindexing."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// verify the value is the object variant before expecting a JSON object\nfn is_object_value(v: &TantivyValue) -> bool {\n    matches!(v, TantivyValue::Object(_))\n}","tryCatchPattern":"match doc_to_json(&mapper, doc, true) {\n    Err(e) if e.to_string().contains(\"has to be a json object\") => {\n        log::warn!(\"field type drifted from schema; treat as scalar: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Re-index after any mapping change that alters a field's type (object <-> text).","Validate documents against the schema before ingest.","Pin schema versions and avoid mixing documents written under older mappings."],"tags":["document","json","rust","search"],"backgroundTag":"type-mismatch","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}