elastic/elasticsearch · error · IllegalArgumentException

field [{}] already exists

Error message

field [{}] already exists

What it means

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.

Source

Thrown at modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RenameProcessor.java:81

    @Override
    public IngestDocument execute(IngestDocument document) {
        String path = document.renderTemplate(field);
        if (path.isEmpty() || document.hasField(path, true) == false) {
            if (ignoreMissing) {
                return document;
            } else {
                throw new IllegalArgumentException("field [" + path + "] doesn't exist");
            }
        }

        // We fail here if the target field point to an array slot that is out of range.
        // If we didn't do this then we would fail if we set the value in the target_field
        // and then on failure processors would not see that value we tried to rename as we already
        // removed it.
        String target = document.renderTemplate(targetField);
        if (document.hasField(target, true) && overrideEnabled == false) {
            throw new IllegalArgumentException("field [" + target + "] already exists");
        }

        Object value = document.getFieldValue(path, Object.class);
        document.removeField(path);
        try {
            document.setFieldValue(target, value);
        } catch (Exception e) {
            // setting the value back to the original field shouldn't as we just fetched it from that field:
            document.setFieldValue(path, value);
            throw e;
        }
        return document;
    }

    @Override
    public String getType() {
        return TYPE;
    }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Enable override: true in the processor config if overwriting the target is intended.
  2. Rename to a target_field that does not collide with existing fields.
  3. Use an on-failure processor or conditional logic to skip when the target exists.

Example fix

// before
{
  "rename": { "field": "old_name", "target_field": "new_name" }
}
// after
{
  "rename": { "field": "old_name", "target_field": "new_name", "override": true }
}
Defensive patterns

Strategy: validation

Validate before calling

// Check the target does not exist before rename (or set override: true)
String target = document.renderTemplate("{{new_name}}");
if (document.hasField(target, true)) {
    // either skip, clear the target, or enable override: true
}

Type guard

boolean targetIsFree(IngestDocument doc, String target) {
    String path = doc.renderTemplate(target);
    return !doc.hasField(path, true);
}

Try / catch

try {
    // run rename processor
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("already exists")) {
        // enable override: true or pick a non-colliding target_field
    } else { throw e; }
}

Prevention

When it happens

Trigger: Running a rename processor where target_field is already populated in the document and the 'override' option is false (the default).

Common situations: Source documents where both the source and target fields are present. Repeated pipeline execution. Field naming collisions between source and target.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/9f839b49566649ab. Report an issue: GitHub.