[Fix] CompletionMapper throws misleading error on null value

closes #6399
This commit is contained in:
Areek Zillur 2014-07-18 15:33:56 -04:00
parent 3c9c9f33e2
commit b81b240924
5 changed files with 49 additions and 0 deletions

View File

@ -286,6 +286,8 @@ public interface FieldMapper<T> extends Mapper {
boolean isSortable();
boolean supportsNullValue();
boolean hasDocValues();
Loading normsLoading(Loading defaultLoading);

View File

@ -842,6 +842,11 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T> {
return true;
}
@Override
public boolean supportsNullValue() {
return true;
}
public boolean hasDocValues() {
return docValues;
}

View File

@ -451,6 +451,11 @@ public class CompletionFieldMapper extends AbstractFieldMapper<String> {
return false;
}
@Override
public boolean supportsNullValue() {
return false;
}
@Override
public FieldType defaultFieldType() {
return Defaults.FIELD_TYPE;

View File

@ -532,6 +532,11 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
// we can only handle null values if we have mappings for them
Mapper mapper = mappers.get(lastFieldName);
if (mapper != null) {
if (mapper instanceof FieldMapper) {
if (!((FieldMapper) mapper).supportsNullValue()) {
throw new MapperParsingException("no object mapping found for null value in [" + lastFieldName + "]");
}
}
mapper.parse(context);
}
}

View File

@ -1039,6 +1039,38 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
}
}
// see issue #6399
@Test
public void testIndexingUnrelatedNullValue() throws Exception {
String mapping = jsonBuilder()
.startObject()
.startObject(TYPE)
.startObject("properties")
.startObject(FIELD)
.field("type", "completion")
.endObject()
.endObject()
.endObject()
.endObject()
.string();
assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping).get());
ensureGreen();
client().prepareIndex(INDEX, TYPE, "1").setSource(FIELD, "strings make me happy", FIELD + "_1", "nulls make me sad")
.setRefresh(true).get();
try {
client().prepareIndex(INDEX, TYPE, "2").setSource(FIELD, null, FIELD + "_1", "nulls make me sad")
.setRefresh(true).get();
fail("Expected MapperParsingException for null value");
} catch (MapperParsingException e) {
// make sure that the exception has the name of the field causing the error
assertTrue(e.getDetailedMessage().contains(FIELD));
}
}
private static String replaceReservedChars(String input, char replacement) {
char[] charArray = input.toCharArray();
for (int i = 0; i < charArray.length; i++) {