{"record":{"id":"9f839b49566649ab","repo":"elastic/elasticsearch","slug":"field-already-exists","errorCode":null,"errorMessage":"field [{}] already exists","messagePattern":"field \\[(.+?)\\] already exists","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RenameProcessor.java","lineNumber":81,"sourceCode":"\n    @Override\n    public IngestDocument execute(IngestDocument document) {\n        String path = document.renderTemplate(field);\n        if (path.isEmpty() || document.hasField(path, true) == false) {\n            if (ignoreMissing) {\n                return document;\n            } else {\n                throw new IllegalArgumentException(\"field [\" + path + \"] doesn't exist\");\n            }\n        }\n\n        // We fail here if the target field point to an array slot that is out of range.\n        // If we didn't do this then we would fail if we set the value in the target_field\n        // and then on failure processors would not see that value we tried to rename as we already\n        // removed it.\n        String target = document.renderTemplate(targetField);\n        if (document.hasField(target, true) && overrideEnabled == false) {\n            throw new IllegalArgumentException(\"field [\" + target + \"] already exists\");\n        }\n\n        Object value = document.getFieldValue(path, Object.class);\n        document.removeField(path);\n        try {\n            document.setFieldValue(target, value);\n        } catch (Exception e) {\n            // setting the value back to the original field shouldn't as we just fetched it from that field:\n            document.setFieldValue(path, value);\n            throw e;\n        }\n        return document;\n    }\n\n    @Override\n    public String getType() {\n        return TYPE;\n    }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RenameProcessor.java#L63-L99","documentation":"Thrown by RenameProcessor.execute when the target field already exists in the document and override (ignore_failure-like 'override' flag) is disabled. This prevents silently clobbering existing data during a rename operation.","triggerScenarios":"Running a rename processor where target_field is already populated in the document and the 'override' option is false (the default).","commonSituations":"Source documents where both the source and target fields are present. Repeated pipeline execution. Field naming collisions between source and target.","solutions":["Enable override: true in the processor config if overwriting the target is intended.","Rename to a target_field that does not collide with existing fields.","Use an on-failure processor or conditional logic to skip when the target exists."],"exampleFix":"// before\n{\n  \"rename\": { \"field\": \"old_name\", \"target_field\": \"new_name\" }\n}\n// after\n{\n  \"rename\": { \"field\": \"old_name\", \"target_field\": \"new_name\", \"override\": true }\n}","handlingStrategy":"validation","validationCode":"// Check the target does not exist before rename (or set override: true)\nString target = document.renderTemplate(\"{{new_name}}\");\nif (document.hasField(target, true)) {\n    // either skip, clear the target, or enable override: true\n}","typeGuard":"boolean targetIsFree(IngestDocument doc, String target) {\n    String path = doc.renderTemplate(target);\n    return !doc.hasField(path, true);\n}","tryCatchPattern":"try {\n    // run rename processor\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"already exists\")) {\n        // enable override: true or pick a non-colliding target_field\n    } else { throw e; }\n}","preventionTips":["Enable override: true when clobbering the target is acceptable.","Choose target_field names that do not collide with existing fields.","Test rename pipelines with documents where both fields are present."],"tags":["elasticsearch","ingest-pipeline","rename","validation"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}