quickwit-oss/quickwit · error · anyhow::Error
the `{key}` value has to be a json object
Error message
the `{key}` value has to be a json object What it means
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.
Source
Thrown at quickwit/quickwit-doc-mapper/src/doc_mapper/doc_mapper_impl.rs:421
let mut values = if let Some(values) = doc.remove(key) {
values
} else {
return Ok(None);
};
if values.len() > 1 {
bail!(
"invalid named document. there are more than 1 value associated to the `{key}` field"
);
}
match values.pop() {
Some(TantivyValue::Object(dynamic_json_obj)) => Ok(Some(
dynamic_json_obj
.into_iter()
.map(|(key, val)| (key, tantivy_value_to_json(val)))
.collect(),
)),
Some(_) => {
bail!("the `{key}` value has to be a json object");
}
None => Ok(None),
}
}
impl DocMapper {
/// Returns the unique identifier of the doc mapping.
pub fn doc_mapping_uid(&self) -> DocMappingUid {
self.doc_mapping_uid
}
/// Validates a JSON object according to the doc mapper.
pub fn validate_json_obj(&self, json_obj: &BorrowedJsonMap) -> Result<(), DocParsingError> {
let is_strict = self.mode.mode_type() == ModeType::Strict;
let mut field_path = Vec::new();
self.field_mappings
.validate_from_json(json_obj, is_strict, &mut field_path)?;
if let Some(timestamp_field_path) = &self.timestamp_field_path {View on GitHub (pinned to a39730c5cd)
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.
Defensive patterns
Strategy: type-guard
Type guard
// verify the value is the object variant before expecting a JSON object
fn is_object_value(v: &TantivyValue) -> bool {
matches!(v, TantivyValue::Object(_))
} Try / catch
match doc_to_json(&mapper, doc, true) {
Err(e) if e.to_string().contains("has to be a json object") => {
log::warn!("field type drifted from schema; treat as scalar: {e}");
}
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- invalid named document. there are more than 1 value associat
- Encountered unknown command: code {other}
- unknown tokenizer `{}` for field `{}`
- failed to assign search jobs: there are no available searche
- failed to assign search jobs: there are no searcher nodes ca
AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08).
Data as JSON: /api/errors/3c169c08c3fa0c9e.
Report an issue: GitHub.