better failure message when failing to find a type mapping for a document loaded from the index

This commit is contained in:
kimchy 2011-02-28 20:21:47 +02:00
parent 3b967040da
commit d395c0a844
2 changed files with 10 additions and 0 deletions

View File

@ -32,6 +32,10 @@ public class TypeMissingException extends IndexException {
super(index, "type[" + type + "] missing");
}
public TypeMissingException(Index index, String type, String message) {
super(index, "type[" + type + "] missing: " + message);
}
@Override public RestStatus status() {
return RestStatus.NOT_FOUND;

View File

@ -25,7 +25,9 @@ import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.*;
import org.elasticsearch.indices.TypeMissingException;
import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.SearchPhase;
@ -79,6 +81,10 @@ public class FetchPhase implements SearchPhase {
DocumentMapper documentMapper = context.mapperService().documentMapper(uid.type());
if (documentMapper == null) {
throw new TypeMissingException(new Index(context.shardTarget().index()), uid.type(), "failed to find type loaded for doc [" + uid.id() + "]");
}
byte[] source = extractSource(doc, documentMapper);
// get the version