Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ public Mapper parse(ParseContext context) throws IOException {
// index
for (Map.Entry<String, CompletionInputMetaData> completionInput : inputMap.entrySet()) {
String input = completionInput.getKey();
if (input.trim().isEmpty()) {
context.addIgnoredField(fieldType.name());
continue;
}
// truncate input
if (input.length() > maxInputLength) {
int len = Math.min(maxInputLength, input.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ 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", BytesReference
.bytes(XContentFactory.jsonBuilder()
.startObject()
.array("completion", " ", "")
.endObject()),
XContentType.JSON));
assertThat(doc.docs().size(), equalTo(1));
assertNull(doc.docs().get(0).get("completion"));
assertNotNull(doc.docs().get(0).getField("_ignored"));
IndexableField ignoredFields = doc.docs().get(0).getField("_ignored");
assertThat(ignoredFields.stringValue(), equalTo("completion"));
}

public void testPrefixQueryType() throws Exception {
Expand Down