elastic/elasticsearch · error · IllegalArgumentException
url parameter [{}] has already been set to [{}]
Error message
url parameter [{}] has already been set to [{}] What it means
Request.addParameter stores query parameters in a map keyed by name and forbids overwriting an existing key, throwing with both the name and the previously-set value. Callers must deliberately set a parameter once; to change it they should build a fresh Request rather than mutate, preventing accidental double-application of filters/params.
Source
Thrown at client/rest/src/main/java/org/elasticsearch/client/Request.java:78
/**
* The path of the request (without scheme, host, port, or prefix).
*/
public String getEndpoint() {
return endpoint;
}
/**
* Add a query string parameter.
* @param name the name of the url parameter. Must not be null.
* @param value the value of the url parameter. If {@code null} then
* the parameter is sent as {@code name} rather than {@code name=value}
* @throws IllegalArgumentException if a parameter with that name has
* already been set
*/
public void addParameter(String name, String value) {
Objects.requireNonNull(name, "url parameter name cannot be null");
if (parameters.containsKey(name)) {
throw new IllegalArgumentException("url parameter [" + name + "] has already been set to [" + parameters.get(name) + "]");
} else {
parameters.put(name, value);
}
}
public void addParameters(Map<String, String> paramSource) {
paramSource.forEach(this::addParameter);
}
/**
* Query string parameters. The returned map is an unmodifiable view of the
* map in the request so calls to {@link #addParameter(String, String)}
* will change it.
*/
public Map<String, String> getParameters() {
return unmodifiableMap(parameters);
}
View on GitHub (pinned to db6a809a66)
Solutions
- Set each parameter at most once; remove the duplicate addParameter call.
- If overriding is intended, construct a new Request and set the final value, or clear parameters first.
- Centralize parameter setting in one builder method to avoid scattered duplicate calls.
Example fix
// before
req.addParameter("size", "10");
req.addParameter("size", "50"); // throws
// after
req.addParameter("size", "50"); // set once Defensive patterns
Strategy: validation
Validate before calling
// Ensure a param is set exactly once per Request:
if (!req.getParameters().containsKey(name)) {
req.addParameter(name, value);
} else {
// build a fresh Request or log a conflict
} Prevention
- Centralize parameter setting in one builder method per request type.
- Don't reuse Request objects across retries; rebuild fresh.
- When merging parameter maps, dedupe by name first.
When it happens
Trigger: Calling req.addParameter("size", "10") twice on the same Request instance; calling addParameters(map) where the map contains a key already added via addParameter; chaining helper builders that each set the same param (e.g. 'pretty', 'filter_path').
Common situations: A request builder helper sets 'filter_path' and the caller also sets it; merging two parameter maps that overlap; reusing a Request object across retries and re-adding params.
Related errors
- can't compare DeadHostStates holding different time supplier
- bufferLimit must be greater than 0
- host cannot be null
- cloudId {} must begin with a human readable identifier follo
- cloudId {} did not decode to a cluster identifier correctly
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/22d6f032012d99e3.
Report an issue: GitHub.