throw a proper exception when no type is found

This commit is contained in:
kimchy 2010-07-22 21:17:11 +03:00
parent 09bbf11605
commit 42c2b6b743
2 changed files with 9 additions and 1 deletions

View File

@ -23,7 +23,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexException;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class TypeMissingException extends IndexException {

View File

@ -25,7 +25,9 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.search.TermFilter;
import org.elasticsearch.common.lucene.search.function.BoostScoreFunction;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.indices.TypeMissingException;
import org.elasticsearch.search.SearchParseElement;
import org.elasticsearch.search.SearchParseException;
import org.elasticsearch.search.SearchPhase;
@ -78,6 +80,9 @@ public class QueryPhase implements SearchPhase {
if (searchContext.types().length == 1) {
String type = searchContext.types()[0];
DocumentMapper docMapper = searchContext.mapperService().documentMapper(type);
if (docMapper == null) {
throw new TypeMissingException(new Index(searchContext.shardTarget().index()), type);
}
Filter typeFilter = new TermFilter(docMapper.typeMapper().term(docMapper.type()));
typeFilter = searchContext.filterCache().cache(typeFilter);
query = new FilteredQuery(query, typeFilter);
@ -85,6 +90,9 @@ public class QueryPhase implements SearchPhase {
BooleanFilter booleanFilter = new BooleanFilter();
for (String type : searchContext.types()) {
DocumentMapper docMapper = searchContext.mapperService().documentMapper(type);
if (docMapper == null) {
throw new TypeMissingException(new Index(searchContext.shardTarget().index()), type);
}
Filter typeFilter = new TermFilter(docMapper.typeMapper().term(docMapper.type()));
typeFilter = searchContext.filterCache().cache(typeFilter);
booleanFilter.add(new FilterClause(typeFilter, BooleanClause.Occur.SHOULD));