elastic/elasticsearch · error · IllegalArgumentException
Sort direction cannot be null
Error message
Sort direction cannot be null
What it means
Thrown by SortOrder.fromString when the provided sort direction string is null. The static factory method explicitly rejects null before checking against 'asc' and 'desc'.
Source
Thrown at modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java:51
public enum SortOrder {
ASCENDING("asc"),
DESCENDING("desc");
private final String direction;
SortOrder(String direction) {
this.direction = direction;
}
@Override
public String toString() {
return this.direction;
}
public static SortOrder fromString(String value) {
if (value == null) {
throw new IllegalArgumentException("Sort direction cannot be null");
}
if (value.equals(ASCENDING.toString())) {
return ASCENDING;
} else if (value.equals(DESCENDING.toString())) {
return DESCENDING;
}
throw new IllegalArgumentException("Sort direction [" + value + "] not recognized." + " Valid values are: [asc, desc]");
}
}
private final String field;
private final SortOrder order;
private final String targetField;
SortProcessor(String tag, String description, String field, SortOrder order, String targetField) {
super(tag, description);
this.field = field;View on GitHub (pinned to db6a809a66)
Solutions
- Provide an explicit 'order' value of 'asc' or 'desc' in the sort processor config.
- Default to 'asc' in your config builder when the user omits the order.
- Validate the order is non-null before constructing the processor.
Example fix
// before
{
"sort": { "field": "events", "target_field": "events_sorted" }
}
// after
{
"sort": { "field": "events", "target_field": "events_sorted", "order": "asc" }
} Defensive patterns
Strategy: validation
Validate before calling
// Validate order is non-null before constructing SortProcessor
String order = config.get("order");
if (order == null) {
order = "asc"; // sensible default
} Type guard
boolean isNonNullOrder(String order) {
return order != null;
} Try / catch
try {
SortOrder.fromString(order);
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("Sort direction cannot be null")) {
order = "asc"; // default
SortOrder.fromString(order);
} else { throw e; }
} Prevention
- Always specify 'order' in the sort processor config.
- Default to 'asc' in config builders when the user omits the order.
- Validate pipeline JSON for required fields before deployment.
When it happens
Trigger: Constructing or configuring a SortProcessor (sort ingest processor) with an order field that is null, or calling SortOrder.fromString(null) directly.
Common situations: Pipeline configuration where the order parameter was omitted and not defaulted. Programmatic construction passing null. JSON config with a missing 'order' key that deserializes to null.
Related errors
- Sort direction [{}] not recognized. Valid values are: [asc,
- field [{}] is null, cannot sort.
- failure store document has unexpected structure, missing req
- failure store document has unexpected structure, missing req
- unable to set domain information for document
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/9036b9c1485b6c13.
Report an issue: GitHub.