elastic/elasticsearch · error · UserException

65

65

Error message

{}

What it means

A generic `{}` placeholder UserException (DATA_ERROR 65) thrown by `add-string` when `keyStore.setString(setting, value)` throws an IllegalArgumentException. That IllegalArgumentException comes from `KeyStoreWrapper.validateSettingName`, which requires names to match `[A-Za-z0-9_\-.]+`. So this error effectively means the setting name failed the allowed-character/pattern check, surfaced via the original exception's message.

Source

Thrown at distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/AddStringKeyStoreCommand.java:74

                prompt = "";
            } else {
                prompt = "Enter value for " + s + ": ";
            }
            return terminal.readSecret(prompt);
        };

        for (final String setting : settings) {
            if (keyStore.getSettingNames().contains(setting) && options.has(forceOption) == false) {
                if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) {
                    terminal.println("Exiting without modifying keystore.");
                    return;
                }
            }

            try {
                keyStore.setString(setting, valueSupplier.apply(setting));
            } catch (final IllegalArgumentException e) {
                throw new UserException(ExitCodes.DATA_ERROR, e.getMessage());
            }
        }

        keyStore.save(env.configDir(), getKeyStorePassword().getChars());
    }

}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Restrict the setting name to `[A-Za-z0-9_\-.]+` — only letters, digits, underscore, hyphen, and dot.
  2. Trim/normalize the name in scripts: `name=${name//[^A-Za-z0-9_.-]/_}`.
  3. Check the official setting name in the Elasticsearch docs for the version you target.

Example fix

// before
bin/elasticsearch-keystore add-string 'my setting'
// after
bin/elasticsearch-keystore add-string my_setting
Defensive patterns

Strategy: validation

Validate before calling

import java.util.regex.Pattern;
private static final Pattern ALLOWED = Pattern.compile("[A-Za-z0-9_\\-.]+");

static String validateSettingName(String name) {
    if (name == null || !ALLOWED.matcher(name).matches()) {
        throw new IllegalArgumentException("Invalid setting name: " + name);
    }
    return name;
}

Try / catch

try {
    keyStore.setString(setting, value);
} catch (IllegalArgumentException e) {
    // surface a clear message; the name violated the allowed pattern
    throw new IllegalArgumentException("Setting name '" + setting + "' must match [A-Za-z0-9_.-]+", e);
}

Prevention

When it happens

Trigger: Passing a setting name containing spaces, slashes, colons, or other invalid characters (e.g. `add-string 'my setting'`); names with shell special chars that survive quoting; copy-pasting a setting key from a different system's namespace.

Common situations: Operators using a setting name that does not correspond to a real Elasticsearch setting key; unicode or whitespace accidentally included; confusable characters.

Related errors


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