@Override public Filter parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.currentToken(); if (token != XContentParser.Token.START_ARRAY) { throw new QueryParsingException(parseContext.index(), "authorizations must be an array."); } List<String> authorizationStrings = new ArrayList<String>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token != XContentParser.Token.VALUE_STRING) { throw new QueryParsingException(parseContext.index(), "authorizations must be an array of strings."); } String authorization = parser.text(); authorizationStrings.add(authorization); } Authorizations authorizations = new Authorizations(authorizationStrings.toArray(new String[authorizationStrings.size()])); List<Filter> filters = new ArrayList<Filter>(); filters.add(new FieldValueFilter(AuthorizationsFilter.VISIBILITY_FIELD_NAME, true)); filters.add(new AuthorizationsFilter(authorizations)); return new OrFilter(filters); } }
/** * 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 Filter parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.currentToken(); if (token != XContentParser.Token.START_ARRAY) { throw new QueryParsingException(parseContext.index(), "authorizations must be an array."); } List<String> authorizationStrings = new ArrayList<String>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token != XContentParser.Token.VALUE_STRING) { throw new QueryParsingException(parseContext.index(), "authorizations must be an array of strings."); } String authorization = parser.text(); authorizationStrings.add(authorization); } Authorizations authorizations = new Authorizations(authorizationStrings.toArray(new String[authorizationStrings.size()])); List<Filter> filters = new ArrayList<Filter>(); filters.add(new FieldValueFilter(AuthorizationsFilter.VISIBILITY_FIELD_NAME, true)); filters.add(new AuthorizationsFilter(authorizations)); return new OrFilter(filters); } }
@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; } } }
@Override public Filter parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.currentToken(); if (token != XContentParser.Token.START_ARRAY) { throw new QueryParsingException(parseContext.index(), "authorizations must be an array."); } List<String> authorizationStrings = new ArrayList<String>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token != XContentParser.Token.VALUE_STRING) { throw new QueryParsingException(parseContext.index(), "authorizations must be an array of strings."); } String authorization = parser.text(); authorizationStrings.add(authorization); } Authorizations authorizations = new Authorizations(authorizationStrings.toArray(new String[authorizationStrings.size()])); List<Filter> filters = new ArrayList<Filter>(); filters.add(new FieldValueFilter(AuthorizationsFilter.VISIBILITY_FIELD_NAME, true)); filters.add(new AuthorizationsFilter(authorizations)); return new OrFilter(filters); } }
@Override public Filter parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); XContentParser.Token token = parser.currentToken(); if (token != XContentParser.Token.START_ARRAY) { throw new QueryParsingException(parseContext.index(), "authorizations must be an array."); } List<String> authorizationStrings = new ArrayList<String>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token != XContentParser.Token.VALUE_STRING) { throw new QueryParsingException(parseContext.index(), "authorizations must be an array of strings."); } String authorization = parser.text(); authorizationStrings.add(authorization); } Authorizations authorizations = new Authorizations(authorizationStrings.toArray(new String[authorizationStrings.size()])); List<Filter> filters = new ArrayList<Filter>(); filters.add(new FieldValueFilter(AuthorizationsFilter.VISIBILITY_FIELD_NAME, true)); filters.add(new AuthorizationsFilter(authorizations)); return new OrFilter(filters); } }
public QueryParsingException(QueryParseContext parseContext, String msg, Throwable cause, Object... args) { super(msg, cause, args); setIndex(parseContext.index()); int lineNumber = UNKNOWN_POSITION; int columnNumber = UNKNOWN_POSITION; XContentParser parser = parseContext.parser(); if (parser != null) { XContentLocation location = parser.getTokenLocation(); if (location != null) { lineNumber = location.lineNumber; columnNumber = location.columnNumber; } } this.columnNumber = columnNumber; this.lineNumber = lineNumber; }
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); String query = this.getQueryString(parser); return this.parse(SirenFieldMapper.SIREN_SOURCE, query, parseContext.analysisService(), parseContext.mapperService(), parseContext.index()); }
parser.nextToken(); if (parser.currentToken() != Token.START_OBJECT) { throw new QueryParsingException(parseContext.index(), "The value of the field " + QUERY + " must be a JSON object containing a SIREn query"); throw new QueryParsingException(parseContext.index(), "JSON query object not properly closed"); throw new QueryParsingException(parseContext.index(), "Invalid query object: unexpected field '" + parser.currentName() + '"'); throw new QueryParsingException(parseContext.index(), "Invalid query object"); return this.parse(queryField, query, parseContext.analysisService(), parseContext.mapperService(), parseContext.index());
@Override public Query termsQuery(List values, QueryParseContext context) { if (context == null) { return super.termsQuery(values, context); } for (Object value : values) { if (isSameIndex(value, context.index().getName())) { // No need to OR these clauses - we can only logically be // running in the context of just one of these index names. return Queries.newMatchAllQuery(); } } // None of the listed index names are this one return Queries.newMatchNoDocsQuery(); }
private static void setDefaultIndexTypeFields(QueryParseContext parseContext, Item item, List<String> moreLikeFields, boolean useDefaultField) { if (item.index() == null) { item.index(parseContext.index().name()); } if (item.type() == null) { if (parseContext.queryTypes().size() > 1) { throw new QueryParsingException(parseContext, "ambiguous type for item with id: " + item.id() + " and index: " + item.index()); } else { item.type(parseContext.queryTypes().iterator().next()); } } // default fields if not present but don't override for artificial docs if ((item.fields() == null || item.fields().length == 0) && item.doc() == null) { if (useDefaultField) { item.fields("*"); } else { item.fields(moreLikeFields.toArray(new String[moreLikeFields.size()])); } } }
/** * This termQuery impl looks at the context to determine the index that * is being queried and then returns a MATCH_ALL_QUERY or MATCH_NO_QUERY * if the value matches this index. This can be useful if aliases or * wildcards are used but the aim is to restrict the query to specific * indices */ @Override public Query termQuery(Object value, @Nullable QueryParseContext context) { if (context == null) { return super.termQuery(value, context); } if (isSameIndex(value, context.index().getName())) { return Queries.newMatchAllQuery(); } else { return Queries.newMatchNoDocsQuery(); } }
throw new QueryParsingException(parseContext.index(), "[image] query malformed, no field"); int limit = -1; String lookupIndex = parseContext.index().name(); String lookupType = null; String lookupId = null; lookupRouting = parser.textOrNull(); } else { throw new QueryParsingException(parseContext.index(), "[image] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext.index(), "No feature specified for image query"); throw new QueryParsingException(parseContext.index(), "No image specified for image query");
currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), indices.toArray(new String[indices.size()])); } else { throw new QueryParsingException(parseContext, "[indices] query does not support [" + currentFieldName + "]"); currentIndexMatchesIndices = matchesIndices(parseContext.index().name(), parser.text()); } else if (parseContext.parseFieldMatcher().match(currentFieldName, NO_MATCH_QUERY)) { String type = parser.text();
throw new QueryParsingException(parseContext.index(), "[query_string] query does not support [" + currentFieldName + "]"); qpSettings.defaultOperator(org.apache.lucene.queryparser.classic.QueryParser.Operator.AND); } else { throw new QueryParsingException(parseContext.index(), "Query default operator [" + op + "] is not allowed"); throw new QueryParsingException(parseContext.index(), "[query_string] analyzer [" + parser.text() + "] not found"); NamedAnalyzer analyzer = parseContext.analysisService().analyzer(parser.text()); if (analyzer == null) { throw new QueryParsingException(parseContext.index(), "[query_string] quote_analyzer [" + parser.text() + "] not found"); qpSettings.timeZone(DateMathParser.parseZone(parser.text())); } catch (IllegalArgumentException e) { throw new QueryParsingException(parseContext.index(), "[query_string] time_zone [" + parser.text() + "] is unknown"); throw new QueryParsingException(parseContext.index(), "[query_string] query does not support [" + currentFieldName + "]"); throw new QueryParsingException(parseContext.index(), "query_string must be provided with a [query]"); throw new QueryParsingException(parseContext.index(), "Failed to parse query [" + qpSettings.queryString() + "]", e);
String currentFieldName = null; String lookupIndex = parseContext.index().name(); String lookupType = null; String lookupId = null;