diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java index 296bdc4410143..a10c2e09849f6 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java @@ -173,6 +173,9 @@ private static MapperParsingException wrapInMapperParsingException(SourceToParse private static String[] splitAndValidatePath(String fullFieldPath) { if (fullFieldPath.contains(".")) { String[] parts = fullFieldPath.split("\\."); + if (parts.length == 0) { + throw new IllegalArgumentException("field name cannot contain only dots"); + } for (String part : parts) { if (Strings.hasText(part) == false) { // check if the field name contains only whitespace diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index fbd9448aa2d5f..249c942142499 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -1656,6 +1656,16 @@ public void testBlankFieldNames() throws Exception { assertThat(err.getCause().getMessage(), containsString("field name cannot be an empty string")); } + public void testDotsOnlyFieldNames() throws Exception { + DocumentMapper mapper = createDocumentMapper(mapping(b -> {})); + MapperParsingException err = expectThrows( + MapperParsingException.class, + () -> mapper.parse(source(b -> b.field(randomFrom(".", "..", "..."), "bar"))) + ); + assertThat(err.getCause(), notNullValue()); + assertThat(err.getCause().getMessage(), containsString("field name cannot contain only dots")); + } + public void testWriteToFieldAlias() throws Exception { DocumentMapper mapper = createDocumentMapper(mapping(b -> { b.startObject("alias-field");