{"record":{"id":"9036b9c1485b6c13","repo":"elastic/elasticsearch","slug":"sort-direction-cannot-be-null","errorCode":null,"errorMessage":"Sort direction cannot be null","messagePattern":"Sort direction cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java","lineNumber":51,"sourceCode":"\n    public enum SortOrder {\n        ASCENDING(\"asc\"),\n        DESCENDING(\"desc\");\n\n        private final String direction;\n\n        SortOrder(String direction) {\n            this.direction = direction;\n        }\n\n        @Override\n        public String toString() {\n            return this.direction;\n        }\n\n        public static SortOrder fromString(String value) {\n            if (value == null) {\n                throw new IllegalArgumentException(\"Sort direction cannot be null\");\n            }\n\n            if (value.equals(ASCENDING.toString())) {\n                return ASCENDING;\n            } else if (value.equals(DESCENDING.toString())) {\n                return DESCENDING;\n            }\n            throw new IllegalArgumentException(\"Sort direction [\" + value + \"] not recognized.\" + \" Valid values are: [asc, desc]\");\n        }\n    }\n\n    private final String field;\n    private final SortOrder order;\n    private final String targetField;\n\n    SortProcessor(String tag, String description, String field, SortOrder order, String targetField) {\n        super(tag, description);\n        this.field = field;","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java#L33-L69","documentation":"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'.","triggerScenarios":"Constructing or configuring a SortProcessor (sort ingest processor) with an order field that is null, or calling SortOrder.fromString(null) directly.","commonSituations":"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.","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."],"exampleFix":"// before\n{\n  \"sort\": { \"field\": \"events\", \"target_field\": \"events_sorted\" }\n}\n// after\n{\n  \"sort\": { \"field\": \"events\", \"target_field\": \"events_sorted\", \"order\": \"asc\" }\n}","handlingStrategy":"validation","validationCode":"// Validate order is non-null before constructing SortProcessor\nString order = config.get(\"order\");\nif (order == null) {\n    order = \"asc\"; // sensible default\n}","typeGuard":"boolean isNonNullOrder(String order) {\n    return order != null;\n}","tryCatchPattern":"try {\n    SortOrder.fromString(order);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Sort direction cannot be null\")) {\n        order = \"asc\"; // default\n        SortOrder.fromString(order);\n    } else { throw e; }\n}","preventionTips":["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."],"tags":["elasticsearch","ingest-pipeline","sort","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}