elastic/elasticsearch · error · IllegalArgumentException
The following fields are not allowed together: {}
Error message
The following fields are not allowed together: {} What it means
Thrown by ensureExclusiveFields when more than one field from a declared exclusive field set is present in the parsed input. Exclusive field sets are registered via declareExclusiveFields and forbid certain field combinations from appearing together in the same object.
Source
Thrown at libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java:356
message.append(" ");
}
message.append("Required one of fields ").append(Arrays.toString(requiredFields.get(i))).append(", but none were specified.");
}
throw new IllegalArgumentException(message.toString());
}
private static void ensureExclusiveFields(List<List<String>> exclusiveFields) {
StringBuilder message = null;
for (List<String> fieldset : exclusiveFields) {
if (fieldset.size() > 1) {
if (message == null) {
message = new StringBuilder();
}
message.append("The following fields are not allowed together: ").append(fieldset).append(" ");
}
}
if (message != null && message.length() > 0) {
throw new IllegalArgumentException(message.toString());
}
}
private void maybeMarkExclusiveField(String currentFieldName, List<List<String>> exclusiveFields) {
for (int i = 0; i < this.exclusiveFieldSets.size(); i++) {
for (String field : this.exclusiveFieldSets.get(i)) {
if (field.equals(currentFieldName)) {
exclusiveFields.get(i).add(currentFieldName);
}
}
}
}
private static void maybeMarkRequiredField(String currentFieldName, List<String[]> requiredFields) {
Iterator<String[]> iter = requiredFields.iterator();
while (iter.hasNext()) {
String[] requiredFieldNames = iter.next();
for (String field : requiredFieldNames) {View on GitHub (pinned to db6a809a66)
Solutions
- Remove all but one field from each exclusive set listed in the error message.
- Consult the API documentation to understand which fields are mutually exclusive.
- If you need behavior from both fields, check whether the endpoint offers a combined alternative.
- Validate the request body against the endpoint's declared exclusive constraints before sending.
Example fix
// before — both script and value provided (exclusive)
{
"runtime": {
"my_field": {
"script": { "source": "emit(1)" },
"value": 42
}
}
}
// after — only one of the exclusive fields
{
"runtime": {
"my_field": {
"script": { "source": "emit(1)" }
}
}
} Defensive patterns
Strategy: validation
Validate before calling
// Before sending, check that no exclusive field sets have >1 member present
List<Set<String>> exclusiveSets = List.of(Set.of("script", "value"));
for (Set<String> exclusive : exclusiveSets) {
long present = exclusive.stream().filter(body::containsKey).count();
if (present > 1) {
throw new IllegalArgumentException("Fields not allowed together: " + exclusive);
}
} Try / catch
try {
objectParser.parse(parser, context);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("not allowed together")) {
return badRequest(e.getMessage());
}
throw e;
} Prevention
- Document mutually exclusive field combinations in your API client wrapper.
- Build request validators that check exclusive constraints before submission.
- When merging configurations from multiple sources, deduplicate exclusive fields.
When it happens
Trigger: Including two or more fields in a request body that the ObjectParser has declared as mutually exclusive. For example, specifying both "script" and "value" in a field mapping where only one is allowed, or sending both "query" and "aggregations" when the endpoint treats them as exclusive.
Common situations: Providing both a shorthand and a detailed form of the same configuration. Copying fields from different examples without realizing they are incompatible. Upgrading to a version where two previously independent fields became exclusive.
Related errors
- Required one of fields {}, but none were specified.
- [{}] Expected START_OBJECT but was: {}
- [{}] failed to parse object
- [{}] doesn't support arrays. Use a single object with multip
- [{}] failed to parse field [{}]
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/c0a0fe35f4af2e83.
Report an issue: GitHub.