diff --git a/src/main/java/org/elasticsearch/index/query/HasChildFilterParser.java b/src/main/java/org/elasticsearch/index/query/HasChildFilterParser.java index 6d18bf2d2c1..e7fc1241edd 100644 --- a/src/main/java/org/elasticsearch/index/query/HasChildFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/HasChildFilterParser.java @@ -134,6 +134,10 @@ public class HasChildFilterParser implements FilterParser { } DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType); + if (parentDocMapper == null) { + throw new QueryParsingException(parseContext.index(), "[has_child] Type [" + childType + "] points to a non existent parent type [" + parentType + "]"); + } + Filter parentFilter = parseContext.cacheFilter(parentDocMapper.typeFilter(), null); HasChildFilter childFilter = new HasChildFilter(query, parentType, childType, parentFilter, searchContext); searchContext.addRewrite(childFilter); diff --git a/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java b/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java index b73c013453a..5d3f3ef21fa 100644 --- a/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java @@ -122,6 +122,10 @@ public class HasChildQueryParser implements QueryParser { String parentType = childDocMapper.parentFieldMapper().type(); DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType); + if (parentDocMapper == null) { + throw new QueryParsingException(parseContext.index(), "[has_child] Type [" + childType + "] points to a non existent parent type [" + parentType + "]"); + } + // wrap the query with type query SearchContext searchContext = SearchContext.current(); if (searchContext == null) {