{"record":{"id":"96fdd28a28497436","repo":"elastic/elasticsearch","slug":"sort-direction-not-recognized-valid-values-a","errorCode":null,"errorMessage":"Sort direction [{}] not recognized. Valid values are: [asc, desc]","messagePattern":"Sort direction \\[(.+?)\\] not recognized\\. Valid values are: \\[asc, desc\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java","lineNumber":59,"sourceCode":"            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;\n        this.order = order;\n        this.targetField = targetField;\n    }\n\n    String getField() {\n        return field;\n    }\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/SortProcessor.java#L41-L77","documentation":"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.","triggerScenarios":"Configuring the sort processor with an order value other than 'asc' or 'desc' (e.g., 'ascending', 'descending', 'ASC', 'DESC', '1', '0').","commonSituations":"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.","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."],"exampleFix":"// before\n{\n  \"sort\": { \"field\": \"events\", \"target_field\": \"events_sorted\", \"order\": \"ascending\" }\n}\n// after\n{\n  \"sort\": { \"field\": \"events\", \"target_field\": \"events_sorted\", \"order\": \"asc\" }\n}","handlingStrategy":"validation","validationCode":"// Normalize and validate order before use\nString order = config.get(\"order\");\nif (order != null) order = order.toLowerCase(Locale.ROOT);\nif (\"asc\".equals(order) || \"desc\".equals(order) == false) {\n    order = \"asc\"; // or reject\n}","typeGuard":"boolean isValidSortOrder(String order) {\n    return \"asc\".equals(order) || \"desc\".equals(order);\n}","tryCatchPattern":"try {\n    SortOrder.fromString(order);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"not recognized\")) {\n        // correct to 'asc' or 'desc'\n    } else { throw e; }\n}","preventionTips":["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."],"tags":["elasticsearch","ingest-pipeline","sort","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}