{"record":{"id":"0150e6ebfc84d6a8","repo":"quickwit-oss/quickwit","slug":"duplicated-field-definition","errorCode":null,"errorMessage":"duplicated field definition `{}`","messagePattern":"duplicated field definition `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-doc-mapper/src/doc_mapper/mapping_tree.rs","lineNumber":1031,"sourceCode":"    let mut field_path = Vec::new();\n    build_mapping_tree_from_entries(entries, &mut field_path, schema)\n}\n\nfn build_mapping_tree_from_entries<'a>(\n    entries: &'a [FieldMappingEntry],\n    field_path: &mut Vec<&'a str>,\n    schema: &mut SchemaBuilder,\n) -> anyhow::Result<MappingNodeRoot> {\n    let mut mapping_node = MappingNode::default();\n    let mut concatenate_fields = Vec::new();\n    let mut concatenate_dynamic_fields = Vec::new();\n    for entry in entries {\n        if let FieldMappingType::Concatenate(_) = &entry.mapping_type {\n            concatenate_fields.push(entry);\n        } else {\n            field_path.push(&entry.name);\n            if mapping_node.branches.contains_key(&entry.name) {\n                bail!(\"duplicated field definition `{}`\", entry.name);\n            }\n            let (child_tree, mut dynamic_fields) =\n                build_mapping_from_field_type(&entry.mapping_type, field_path, schema)?;\n            field_path.pop();\n            mapping_node.insert(&entry.name, child_tree);\n            concatenate_dynamic_fields.append(&mut dynamic_fields);\n        }\n    }\n    for concatenate_field_entry in concatenate_fields {\n        let FieldMappingType::Concatenate(options) = &concatenate_field_entry.mapping_type else {\n            // we only pushed Concatenate fields in `concatenate_fields`\n            unreachable!();\n        };\n        let name = &concatenate_field_entry.name;\n        if mapping_node.branches.contains_key(name) {\n            bail!(\"duplicated field definition `{}`\", name);\n        }\n        let text_options: JsonObjectOptions = options.clone().into();","sourceCodeStart":1013,"sourceCodeEnd":1049,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-doc-mapper/src/doc_mapper/mapping_tree.rs#L1013-L1049","documentation":"While building the mapping tree from the field mapping entries, two entries resolved to the same field path (e.g. an explicit field colliding with a property defined via an object/JSON subtree). The schema builder cannot hold two definitions for one field, so the duplicate is rejected with its full name.","triggerScenarios":"Calling build_mapping_tree (index config load / DocMapping validation) with a mapping containing two fields of the same name in the same object, e.g. `message` declared twice, including duplicates arising from nested objects each contributing a child of the same name.","commonSituations":"Merged index configs where two include files define the same field; YAML anchors or generated mappings appending a field twice; a copy-pasted field block left in place during edits.","solutions":["Remove or rename the duplicate field definition in the index config mapping.","If merging configs programmatically, deduplicate entries by name before building the tree.","Search the YAML/JSON mapping for repeated keys (some editors hide duplicate keys)."],"exampleFix":"// before\nmapping:\n  message:\n    type: text\n  message:\n    type: json\n// after\nmapping:\n  message:\n    type: text","handlingStrategy":"validation","validationCode":"fn check_duplicate_fields(mapping: &serde_yaml::Mapping) -> Result<(), String> {\n    let mut seen = std::collections::HashSet::new();\n    for (k, _) in mapping {\n        if !seen.insert(k.clone()) {\n            return Err(format!(\"duplicated field definition `{k:?}`\"));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"duplicated field definition\") => {\n        // surface the offending config path to the user\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Deduplicate entries when merging mapping configs.","Use an editor/linter that highlights duplicate YAML keys.","Review include/merge logic for double-added field blocks."],"tags":["index-config","duplicate-key","validation"],"backgroundTag":"schema-validation-failed","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"}