private void validateAliasFilter(XContentParser parser, IndexQueryParserService indexQueryParserService) throws IOException { QueryParseContext context = indexQueryParserService.getParseContext(); try { context.reset(parser); context.parseInnerFilter(); } finally { context.reset(null); parser.close(); } } }
public NestedInnerQueryParseSupport(XContentParser parser, SearchContext searchContext) { parseContext = searchContext.queryParserService().getParseContext(); parseContext.reset(parser); }
private ParsedQuery innerParse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException { XContentParser originalParser = parseContext.parser(); parseContext.reset(parser); try { parseContext.parseFieldMatcher(parseFieldMatcher); Query query = parseContext.parseInnerQuery(); if (query == null) { query = Queries.newMatchNoDocsQuery(); } return new ParsedQuery(query, parseContext.copyNamedQueries()); } finally { parseContext.reset(originalParser); } }
/** * Parses an inner filter, returning null if the filter should be ignored. */ @Nullable public ParsedQuery parseInnerFilter(XContentParser parser) throws IOException { QueryParseContext context = cache.get(); XContentParser originalParser = context.parser(); context.reset(parser); try { Query filter = context.parseInnerFilter(); if (filter == null) { return null; } return new ParsedQuery(filter, context.copyNamedQueries()); } finally { context.reset(originalParser); } }
@Override public void parse(XContentParser parser, SearchContext searchContext) throws Exception { QueryParseContext context = searchContext.queryParserService().getParseContext(); context.reset(parser); Map<String, InnerHitsContext.BaseInnerHits> topLevelInnerHits = parseInnerHits(parser, context, searchContext); if (topLevelInnerHits != null) { InnerHitsContext innerHitsContext = searchContext.innerHits(); innerHitsContext.addInnerHitDefinitions(topLevelInnerHits); } }
/** * Parses the template query replacing template parameters with provided * values. Handles both submitting the template as part of the request as * well as referencing only the template name. * * @param parseContext * parse context containing the templated query. */ @Override @Nullable public Query parse(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); Template template = parse(parser, parseContext.parseFieldMatcher()); ExecutableScript executable = this.scriptService.executable(template, ScriptContext.Standard.SEARCH, SearchContext.current(), Collections.<String, String>emptyMap()); BytesReference querySource = (BytesReference) executable.run(); try (XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource)) { final QueryParseContext context = new QueryParseContext(parseContext.index(), parseContext.indexQueryParserService()); context.reset(qSourceParser); return context.parseInnerQuery(); } }
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.nextToken(); if (token != XContentParser.Token.FIELD_NAME) { throw new QueryParsingException(parseContext, "[wrapper] query malformed"); } String fieldName = parser.currentName(); if (!fieldName.equals("query")) { throw new QueryParsingException(parseContext, "[wrapper] query malformed"); } parser.nextToken(); byte[] querySource = parser.binaryValue(); try (XContentParser qSourceParser = XContentFactory.xContent(querySource).createParser(querySource)) { final QueryParseContext context = new QueryParseContext(parseContext.index(), parseContext.indexQueryParserService()); context.reset(qSourceParser); Query result = context.parseInnerQuery(); parser.nextToken(); parseContext.combineNamedQueries(context); return result; } } }