{"record":{"id":"1dd7a14fd6ac2cff","repo":"elastic/elasticsearch","slug":"invalid-mapping-rule-rule-only-a-single-cha","errorCode":null,"errorMessage":"Invalid Mapping Rule : [{rule}]. Only a single character is allowed.","messagePattern":"Invalid Mapping Rule : \\[(.+?)\\]\\. Only a single character is allowed\\.","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterTokenFilterFactory.java","lineNumber":121,"sourceCode":"        return 0;\n    }\n\n    // source => type\n    private static final Pattern typePattern = Pattern.compile(\"(.*)\\\\s*=>\\\\s*(.*)\\\\s*$\");\n\n    /**\n     * parses a list of MappingCharFilter style rules into a custom byte[] type table\n     */\n    static byte[] parseTypes(Collection<String> rules) {\n        SortedMap<Character, Byte> typeMap = new TreeMap<>();\n        for (String rule : rules) {\n            Matcher m = typePattern.matcher(rule);\n            if (m.find() == false) {\n                throw new RuntimeException(\"Invalid Mapping Rule : [\" + rule + \"]\");\n            }\n            String lhs = parseString(m.group(1).trim());\n            Byte rhs = parseType(m.group(2).trim());\n            if (lhs.length() != 1) throw new RuntimeException(\"Invalid Mapping Rule : [\" + rule + \"]. Only a single character is allowed.\");\n            if (rhs == null) throw new RuntimeException(\"Invalid Mapping Rule : [\" + rule + \"]. Illegal type.\");\n            typeMap.put(lhs.charAt(0), rhs);\n        }\n\n        // ensure the table is always at least as big as DEFAULT_WORD_DELIM_TABLE for performance\n        byte types[] = new byte[Math.max(typeMap.lastKey() + 1, WordDelimiterIterator.DEFAULT_WORD_DELIM_TABLE.length)];\n        for (int i = 0; i < types.length; i++) {\n            types[i] = WordDelimiterIterator.getType(i);\n        }\n        for (Map.Entry<Character, Byte> mapping : typeMap.entrySet()) {\n            types[mapping.getKey()] = mapping.getValue();\n        }\n        return types;\n    }\n\n    private static Byte parseType(String s) {\n        if (s.equals(\"LOWER\")) return WordDelimiterFilter.LOWER;\n        else if (s.equals(\"UPPER\")) return WordDelimiterFilter.UPPER;","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/WordDelimiterTokenFilterFactory.java#L103-L139","documentation":"After a type_table rule matches the regex, the left-hand side is run through parseString (handling escapes) and must yield exactly one character. If lhs.length() != 1 parseTypes throws RuntimeException. Multi-character LHS is structurally invalid because each rule maps a single char to a single byte type.","triggerScenarios":"A type_table entry whose LHS decodes to two or more characters: \"abc => LOWER\", \".. => DIGIT\", or an escape that resolves to a surrogate pair.","commonSituations":"Trying to map a whole word or punctuation sequence to a type; misunderstanding that type_table is per-character.","solutions":["Provide exactly one character (or one escape sequence) on the LHS of each rule.","For multi-character patterns use a different mechanism (protected words, custom analyzer), not type_table.","Re-validate each entry's LHS length."],"exampleFix":"// before\n\"type_table\": [\"abc => ALPHA\"]\n// after\n\"type_table\": [\"a => ALPHA\", \"b => ALPHA\", \"c => ALPHA\"]","handlingStrategy":"validation","validationCode":"// After resolving escapes, each LHS must be exactly one char\nstatic List<String> badLhs(List<String> typeTable) {\n  return typeTable.stream()\n    .map(r -> r.split(\"=>\", 2)[0].trim())\n    .filter(lhs -> resolveEscapes(lhs).length() != 1)\n    .toList();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember type_table maps one character to one type — not sequences.","Use protected_words or a different filter for multi-char patterns."],"tags":["analysis","word-delimiter","type-table","validation"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}