diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/TypeMissingException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/TypeMissingException.java index b6eeb8f2e7f..81e1c675b24 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/TypeMissingException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/TypeMissingException.java @@ -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 { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java index 63d48fc7032..913e69ec8df 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -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));