private Query parseQuery(String type, XContentParser parser) {
String[] previousTypes = null;
if (type != null) {
QueryParseContext.setTypesWithPrevious(new String[]{type});
}
QueryParseContext context = cache.get();
try {
context.reset(parser);
context.setAllowUnmappedFields(allowUnmappedFields);
return queryParserService.parseInnerQuery(context);
} catch (IOException e) {
throw new QueryParsingException(queryParserService.index(), "Failed to parse", e);
} finally {
if (type != null) {
QueryParseContext.setTypes(previousTypes);
}
context.reset(null);
}
}