Skip to content

Commit abf2268

Browse files
committed
Added an error message for when child mapping is not properly configured (incorrect type)
1 parent c37de66 commit abf2268

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/main/java/org/elasticsearch/index/query/HasChildFilterParser.java

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
134134
}
135135

136136
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
137+
if (parentDocMapper == null) {
138+
throw new QueryParsingException(parseContext.index(), "[has_child] Type [" + childType + "] points to a non existent parent type [" + parentType + "]");
139+
}
140+
137141
Filter parentFilter = parseContext.cacheFilter(parentDocMapper.typeFilter(), null);
138142
HasChildFilter childFilter = new HasChildFilter(query, parentType, childType, parentFilter, searchContext);
139143
searchContext.addRewrite(childFilter);

src/main/java/org/elasticsearch/index/query/HasChildQueryParser.java

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
122122
String parentType = childDocMapper.parentFieldMapper().type();
123123
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
124124

125+
if (parentDocMapper == null) {
126+
throw new QueryParsingException(parseContext.index(), "[has_child] Type [" + childType + "] points to a non existent parent type [" + parentType + "]");
127+
}
128+
125129
// wrap the query with type query
126130
SearchContext searchContext = SearchContext.current();
127131
if (searchContext == null) {

0 commit comments

Comments
 (0)