diff --git a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java index 186334c85cb33..e526ef942ca2c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java @@ -457,6 +457,10 @@ public Mapper parse(ParseContext context) throws IOException { } input = input.substring(0, len); } + if (input.length() == 0) { + // Ignore empty inputs + continue; + } CompletionInputMetaData metaData = completionInput.getValue(); if (fieldType().hasContextMappings()) { fieldType().getContextMappings().addField(context.doc(), fieldType().name(), diff --git a/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java index 74183ae864a60..6c5a525463c88 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java @@ -395,6 +395,16 @@ public void testFieldValueValidation() throws Exception { assertThat(cause, instanceOf(IllegalArgumentException.class)); assertThat(cause.getMessage(), containsString("[0x1e]")); } + + // empty inputs are ignored + ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder() + .startObject() + .field("completion", "") + .endObject() + .bytes(), + XContentType.JSON)); + assertThat(doc.docs().size(), equalTo(1)); + assertNull(doc.docs().get(0).get("completion")); } public void testPrefixQueryType() throws Exception {