elastic/elasticsearch · error · IllegalArgumentException
field [{}] is null, cannot sort.
Error message
field [{}] is null, cannot sort. What it means
Thrown by SortProcessor.execute when the configured field resolves to a null value (the field is absent or explicitly null). The processor cannot sort a null list, so it fails fast. Note this processor has no ignore_missing option.
Source
Thrown at modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java:92
String getField() {
return field;
}
SortOrder getOrder() {
return order;
}
String getTargetField() {
return targetField;
}
@Override
@SuppressWarnings("unchecked")
public IngestDocument execute(IngestDocument document) {
List<? extends Comparable<Object>> list = document.getFieldValue(field, List.class);
if (list == null) {
throw new IllegalArgumentException("field [" + field + "] is null, cannot sort.");
}
List<? extends Comparable<Object>> copy = new ArrayList<>(list);
if (order.equals(SortOrder.ASCENDING)) {
Collections.sort(copy);
} else {
Collections.sort(copy, Collections.reverseOrder());
}
document.setFieldValue(targetField, copy);
return document;
}
@Override
public String getType() {
return TYPE;
}View on GitHub (pinned to db6a809a66)
Solutions
- Wrap the sort processor in an on-failure handler to tolerate missing fields.
- Add a conditional check (script/grok processor) to only route documents with the field present to this pipeline.
- Use a different processor pattern that supports ignore_missing, or pre-populate the field with an empty list.
Example fix
// before: sort fails when 'events' is absent
{
"sort": { "field": "events", "target_field": "events_sorted", "order": "asc" }
}
// after: guard with a conditional pipeline branch or on-failure
{
"pipeline": {
"processors": [
{ "if": "ctx.events != null", "sort": { "field": "events", "target_field": "events_sorted", "order": "asc" } }
]
}
} Defensive patterns
Strategy: validation
Validate before calling
// Guard the sort processor with a conditional check
// In pipeline JSON, use an 'if' condition:
// { "if": "ctx.events != null", "sort": { ... } }
Object val = document.getFieldValue("events", Object.class, true);
if (val == null) {
// skip sort; field is absent
} Type guard
boolean hasSortabbleList(IngestDocument doc, String field) {
Object v = doc.getFieldValue(field, Object.class, true);
return v instanceof List;
} Try / catch
try {
// run sort processor
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("is null, cannot sort")) {
// add an 'if' condition or on-failure handler
} else { throw e; }
} Prevention
- Wrap the sort processor in an 'if' condition checking the field is non-null.
- Use an on-failure handler since sort has no ignore_missing option.
- Pre-populate optional list fields with empty lists upstream.
When it happens
Trigger: Running the sort processor on a document where the configured source field is absent or null. Unlike split/user-agent processors, sort does not support ignore_missing, so any null input is fatal.
Common situations: Optional list fields that are sometimes absent. Documents where the field was removed by an upstream processor. Schema-optional array fields.
Related errors
- Sort direction cannot be null
- Sort direction [{}] not recognized. Valid values are: [asc,
- field [{}] is null, cannot split.
- field [{}] is null, cannot parse user-agent.
- field [{}] is null, cannot extract geoip information.
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/af14e7632c4ecec0.
Report an issue: GitHub.