[Fix] CompletionMapper throws misleading error on null value
closes #6399
This commit is contained in:
parent
3c9c9f33e2
commit
b81b240924
|
@ -286,6 +286,8 @@ public interface FieldMapper<T> extends Mapper {
|
||||||
|
|
||||||
boolean isSortable();
|
boolean isSortable();
|
||||||
|
|
||||||
|
boolean supportsNullValue();
|
||||||
|
|
||||||
boolean hasDocValues();
|
boolean hasDocValues();
|
||||||
|
|
||||||
Loading normsLoading(Loading defaultLoading);
|
Loading normsLoading(Loading defaultLoading);
|
||||||
|
|
|
@ -842,6 +842,11 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsNullValue() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasDocValues() {
|
public boolean hasDocValues() {
|
||||||
return docValues;
|
return docValues;
|
||||||
}
|
}
|
||||||
|
|
|
@ -451,6 +451,11 @@ public class CompletionFieldMapper extends AbstractFieldMapper<String> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsNullValue() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldType defaultFieldType() {
|
public FieldType defaultFieldType() {
|
||||||
return Defaults.FIELD_TYPE;
|
return Defaults.FIELD_TYPE;
|
||||||
|
|
|
@ -532,6 +532,11 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll {
|
||||||
// we can only handle null values if we have mappings for them
|
// we can only handle null values if we have mappings for them
|
||||||
Mapper mapper = mappers.get(lastFieldName);
|
Mapper mapper = mappers.get(lastFieldName);
|
||||||
if (mapper != null) {
|
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);
|
mapper.parse(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
private static String replaceReservedChars(String input, char replacement) {
|
||||||
char[] charArray = input.toCharArray();
|
char[] charArray = input.toCharArray();
|
||||||
for (int i = 0; i < charArray.length; i++) {
|
for (int i = 0; i < charArray.length; i++) {
|
||||||
|
|
Loading…
Reference in New Issue