Throw a more meaningful message when no document is specified for indexing
This commit is contained in:
parent
a52e01f3e5
commit
ed43ad07d7
|
@ -537,6 +537,11 @@ public class DocumentMapper implements ToXContent {
|
|||
throw (MapperParsingException) e;
|
||||
}
|
||||
|
||||
// Throw a more meaningful message if the document is empty.
|
||||
if (source.source() != null && source.source().length() == 0) {
|
||||
throw new MapperParsingException("failed to parse, document is empty");
|
||||
}
|
||||
|
||||
throw new MapperParsingException("failed to parse", e);
|
||||
} finally {
|
||||
// only close the parser when its not provided externally
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.mapper.Uid;
|
||||
import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -113,4 +114,21 @@ public class SimpleMapperTests {
|
|||
DocumentMapper builtDocMapper = MapperTests.newParser().parse(builtMapping);
|
||||
assertThat((String) builtDocMapper.meta().get("param1"), equalTo("value1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoDocumentSent() throws Exception {
|
||||
DocumentMapperParser mapperParser = MapperTests.newParser();
|
||||
DocumentMapper docMapper = doc("test",
|
||||
rootObject("person")
|
||||
.add(object("name").add(stringField("first").store(true).index(false)))
|
||||
).build(mapperParser);
|
||||
|
||||
BytesReference json = new BytesArray("".getBytes());
|
||||
try {
|
||||
docMapper.parse("person", "1", json).rootDoc();
|
||||
assertThat("this point is never reached", false);
|
||||
} catch (MapperParsingException e) {
|
||||
assertThat(e.getMessage(), equalTo("failed to parse, document is empty"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue