elastic/elasticsearch · error · IllegalArgumentException
Sort direction [{}] not recognized. Valid values are: [asc,
Error message
Sort direction [{}] not recognized. Valid values are: [asc, desc] What it means
Thrown by SortOrder.fromString when the sort direction string is non-null but does not match either 'asc' or 'desc'. Only those two exact values are accepted.
Source
Thrown at modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java:59
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;
this.order = order;
this.targetField = targetField;
}
String getField() {
return field;
}
View on GitHub (pinned to db6a809a66)
Solutions
- Use exactly 'asc' or 'desc' (lowercase) as the order value.
- Normalize the input to lowercase 'asc'/'desc' before passing it to the processor.
- Correct any typo in the order field.
Example fix
// before
{
"sort": { "field": "events", "target_field": "events_sorted", "order": "ascending" }
}
// after
{
"sort": { "field": "events", "target_field": "events_sorted", "order": "asc" }
} Defensive patterns
Strategy: validation
Validate before calling
// Normalize and validate order before use
String order = config.get("order");
if (order != null) order = order.toLowerCase(Locale.ROOT);
if ("asc".equals(order) || "desc".equals(order) == false) {
order = "asc"; // or reject
} Type guard
boolean isValidSortOrder(String order) {
return "asc".equals(order) || "desc".equals(order);
} Try / catch
try {
SortOrder.fromString(order);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("not recognized")) {
// correct to 'asc' or 'desc'
} else { throw e; }
} Prevention
- Use exactly 'asc' or 'desc' (lowercase).
- Lowercase and validate user-supplied order values before constructing the processor.
- Document the accepted values clearly in pipeline specs.
When it happens
Trigger: Configuring the sort processor with an order value other than 'asc' or 'desc' (e.g., 'ascending', 'descending', 'ASC', 'DESC', '1', '0').
Common situations: Using verbose direction names ('ascending'/'descending') instead of short forms. Case sensitivity issues (the check is case-sensitive). Typos. Copy-paste from other tools that use different sort vocabularies.
Related errors
- Sort direction cannot be null
- 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/96fdd28a28497436.
Report an issue: GitHub.