elastic/elasticsearch · error · IllegalArgumentException
Required one of fields {}, but none were specified.
Error message
Required one of fields {}, but none were specified. What it means
Thrown by throwMissingRequiredFields after the ObjectParser finishes consuming all fields and discovers that at least one declared required-field set has zero members present in the input. A required-field set is registered via declareRequiredFieldSet and mandates that at least one field from the set appear in every valid document.
Source
Thrown at libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java:342
if (requiredFields != null && requiredFields.isEmpty() == false) {
throwMissingRequiredFields(requiredFields);
}
return value;
}
private void throwExpectedStartObject(XContentParser parser, XContentParser.Token token) {
throw new XContentParseException(parser.getTokenLocation(), "[" + name + "] Expected START_OBJECT but was: " + token);
}
private static void throwMissingRequiredFields(List<String[]> requiredFields) {
final StringBuilder message = new StringBuilder();
for (int i = 0; i < requiredFields.size(); i++) {
if (i > 0) {
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) {View on GitHub (pinned to db6a809a66)
Solutions
- Read the error message to see which field set is required and add at least one field from that set.
- Check the API documentation for required fields on the endpoint you are calling.
- Use the endpoint's schema or OpenAPI spec to discover required field groups.
- If the field group should not be required, verify the ObjectParser configuration in the server code.
Example fix
// before — missing required field
PUT /my-index
{
"mappings": { "properties": { "name": { "type": "text" } } }
}
// after — required field included (if the parser required it)
PUT /my-index
{
"settings": { "number_of_shards": 1 },
"mappings": { "properties": { "name": { "type": "text" } } }
} Defensive patterns
Strategy: validation
Validate before calling
// Before sending, check that at least one field from each required set is present
List<Set<String>> requiredSets = List.of(Set.of("number_of_shards", "number_of_replicas"));
for (Set<String> required : requiredSets) {
if (required.stream().noneMatch(body::containsKey)) {
throw new IllegalArgumentException("Missing required field from: " + required);
}
} Try / catch
try {
objectParser.parse(parser, context);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("Required one of fields")) {
return badRequest(e.getMessage());
}
throw e;
} Prevention
- Review API documentation for required field sets before constructing request bodies.
- Build client-side request builders that enforce required fields at compile time.
- Write integration tests that verify requests fail with clear messages when required fields are missing.
When it happens
Trigger: Sending a request body to an endpoint whose ObjectParser declared required field sets (via declareRequiredFieldSet) but omitting every field from at least one of those sets. For example, a settings update that requires at least one of ["number_of_shards", "number_of_replicas"] but provides neither.
Common situations: Omitting a mandatory field group from an index creation or settings update request. Copying a partial template from documentation that does not include the required field. Assuming a field is optional when the parser marks it as required.
Related errors
- The following fields are not allowed together: {}
- [{}] 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/22d283ba5206ac36.
Report an issue: GitHub.