{"record":{"id":"204ddfe677aeb108","repo":"elastic/elasticsearch","slug":"is-not-a-valid-field-reference","errorCode":null,"errorMessage":"'{}' is not a valid field reference","messagePattern":"'(.+?)' is not a valid field reference","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RerouteProcessor.java","lineNumber":248,"sourceCode":"\n        public static DataStreamValueSource type(String type) {\n            return new DataStreamValueSource(type, DataStream::sanitizeType);\n        }\n\n        public static DataStreamValueSource dataset(String dataset) {\n            return new DataStreamValueSource(dataset, DataStream::sanitizeDataset);\n        }\n\n        public static DataStreamValueSource namespace(String namespace) {\n            return new DataStreamValueSource(namespace, DataStream::sanitizeNamespace);\n        }\n\n        private DataStreamValueSource(String value, Function<String, String> sanitizer) {\n            this.sanitizer = sanitizer;\n            this.value = value;\n            if (value.contains(\"{{\") || value.contains(\"}}\")) {\n                if (value.startsWith(\"{{\") == false || value.endsWith(\"}}\") == false) {\n                    throw new IllegalArgumentException(\"'\" + value + \"' is not a valid field reference\");\n                }\n                String fieldReference = value.substring(2, value.length() - 2);\n                // field references may have two or three curly braces\n                if (fieldReference.startsWith(\"{\") && fieldReference.endsWith(\"}\")) {\n                    fieldReference = fieldReference.substring(1, fieldReference.length() - 1);\n                }\n                fieldReference = fieldReference.trim();\n                // only a single field reference is allowed\n                // so something like this is disallowed: {{foo}}-{{bar}}\n                if (fieldReference.contains(\"{\") || fieldReference.contains(\"}\")) {\n                    throw new IllegalArgumentException(\"'\" + value + \"' is not a valid field reference\");\n                }\n                this.fieldReference = fieldReference;\n            } else {\n                this.fieldReference = null;\n                if (Objects.equals(sanitizer.apply(value), value) == false) {\n                    throw new IllegalArgumentException(\"'\" + value + \"' contains disallowed characters\");\n                }","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RerouteProcessor.java#L230-L266","documentation":"Thrown in the DataStreamValueSource constructor when a value contains mustache-style field-reference markers ('{{' or '}}') but does not strictly start with '{{' and end with '}}'. This guards against malformed field references in reroute type/dataset/namespace config.","triggerScenarios":"Configuring reroute with a type, dataset, or namespace value like 'foo{{bar' or '{{foo}}-{{bar}}' that includes curly markers but is not a single clean field reference of the form '{{fieldname}}' or '{{{fieldname}}}'.","commonSituations":"Attempting to interpolate multiple fields in one segment (e.g., '{{a}}-{{b}}'). Using unbalanced or stray curly braces in static values. Copy-paste errors from mustache templates.","solutions":["Use a single complete field reference: '{{field_name}}' or '{{{field_name}}}'.","For static (non-interpolated) values, remove all '{{' and '}}' markers.","If you need multiple fields, resolve them upstream with a script processor and reference the combined result."],"exampleFix":"// before\n{\n  \"reroute\": { \"dataset\": \"{{service}}-{{env}}\" }\n}\n// after (use a single field, or precompute upstream)\n{\n  \"reroute\": { \"dataset\": \"{{service_and_env}}\" }\n}","handlingStrategy":"validation","validationCode":"// Validate a reroute field reference value is well-formed\nString v = \"{{service}}\"; // example config value\nif (v.contains(\"{{\") || v.contains(\"}}\")) {\n    if (!v.startsWith(\"{{\") || !v.endsWith(\"}}\")) {\n        throw new IllegalArgumentException(\"malformed field reference: \" + v);\n    }\n}","typeGuard":"boolean isWellFormedFieldRef(String value) {\n    if (value == null) return false;\n    if (value.contains(\"{{\") || value.contains(\"}}\")) {\n        return value.startsWith(\"{{\") && value.endsWith(\"}}\");\n    }\n    return true;\n}","tryCatchPattern":"try {\n    // build/run reroute processor config\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"is not a valid field reference\")) {\n        // fix config: use a single complete {{field}} reference\n    } else { throw e; }\n}","preventionTips":["Format field references as exactly '{{fieldname}}' or '{{{fieldname}}}'.","Avoid mixing static text and field references in one segment.","Pre-combine multiple fields upstream with a script processor."],"tags":["elasticsearch","ingest-pipeline","reroute","data-stream","template","validation"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}