Ensure empty completion entries are never indexed

closes #10987
This commit is contained in:
Areek Zillur 2015-05-13 20:01:16 -04:00
parent df59288b72
commit af6b69e791
2 changed files with 34 additions and 0 deletions

View File

@ -369,6 +369,9 @@ public class CompletionFieldMapper extends AbstractFieldMapper<String> {
payload = payload == null ? EMPTY : payload;
if (surfaceForm == null) { // no surface form use the input
for (String input : inputs) {
if (input.length() == 0) {
continue;
}
BytesRef suggestPayload = analyzingSuggestLookupProvider.buildPayload(new BytesRef(
input), weight, payload);
context.doc().add(getCompletionField(ctx, input, suggestPayload));
@ -377,6 +380,9 @@ public class CompletionFieldMapper extends AbstractFieldMapper<String> {
BytesRef suggestPayload = analyzingSuggestLookupProvider.buildPayload(new BytesRef(
surfaceForm), weight, payload);
for (String input : inputs) {
if (input.length() == 0) {
continue;
}
context.doc().add(getCompletionField(ctx, input, suggestPayload));
}
}

View File

@ -435,6 +435,34 @@ public class ContextSuggestSearchTests extends ElasticsearchIntegrationTest {
}
@Test // see issue #10987
public void testEmptySuggestion() throws Exception {
String mapping = jsonBuilder()
.startObject()
.startObject(TYPE)
.startObject("properties")
.startObject(FIELD)
.field("type", "completion")
.startObject("context")
.startObject("type_context")
.field("path", "_type")
.field("type", "category")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.string();
assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping).get());
ensureGreen();
client().prepareIndex(INDEX, TYPE, "1").setSource(FIELD, "")
.setRefresh(true).get();
}
@Test
public void testMultiValueField() throws Exception {
assertAcked(prepareCreate(INDEX).addMapping(TYPE, createMapping(TYPE, ContextBuilder.reference("st", "category"))));