Added an error message for when child mapping is not properly configured (incorrect type)

This commit is contained in:
Boaz Leskes 2013-07-09 14:04:07 +02:00
parent c37de66fb6
commit abf2268574
2 changed files with 8 additions and 0 deletions

View File

@ -134,6 +134,10 @@ public class HasChildFilterParser implements FilterParser {
} }
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType); 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); Filter parentFilter = parseContext.cacheFilter(parentDocMapper.typeFilter(), null);
HasChildFilter childFilter = new HasChildFilter(query, parentType, childType, parentFilter, searchContext); HasChildFilter childFilter = new HasChildFilter(query, parentType, childType, parentFilter, searchContext);
searchContext.addRewrite(childFilter); searchContext.addRewrite(childFilter);

View File

@ -122,6 +122,10 @@ public class HasChildQueryParser implements QueryParser {
String parentType = childDocMapper.parentFieldMapper().type(); String parentType = childDocMapper.parentFieldMapper().type();
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType); 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 // wrap the query with type query
SearchContext searchContext = SearchContext.current(); SearchContext searchContext = SearchContext.current();
if (searchContext == null) { if (searchContext == null) {