Query Refactoring: remove deprecated methods and temporary classes
After all queries now have a `toQuery` method and the parsers all support `fromXContent` it is possible to remove the following workarounds and deprecated methods we kept around while doing the refactoring: * remove the BaseQueryParser and BaseQueryParserTemp. All parsers implement QueryParser directly now * remove deprecated methods in QueryParseContext that either returned a Query or a Filter. * remove the temporary QueryWrapperQueryBuilder Relates to #10217
This commit is contained in:
parent
dbb01f5b43
commit
eb8ea63626
|
@ -145,7 +145,7 @@ public class AliasValidator extends AbstractComponent {
|
|||
QueryShardContext context = indexQueryParserService.getShardContext();
|
||||
try {
|
||||
context.reset(parser);
|
||||
context.parseContext().parseInnerFilter();
|
||||
context.parseContext().parseInnerQueryBuilder().toFilter(context);
|
||||
} finally {
|
||||
context.reset(null);
|
||||
parser.close();
|
||||
|
|
|
@ -109,10 +109,7 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder> exte
|
|||
return result;
|
||||
}
|
||||
|
||||
//norelease to be made abstract once all query builders override doToQuery providing their own specific implementation.
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
return context.indexQueryParserService().indicesQueriesRegistry().queryParsers().get(getName()).parse(context);
|
||||
}
|
||||
protected abstract Query doToQuery(QueryShardContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the query name for the query.
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Class used during the query parsers refactoring. Will be removed once we can parse search requests on the coordinating node.
|
||||
* All query parsers that have a refactored "fromXContent" method can be changed to extend this instead of {@link BaseQueryParserTemp}.
|
||||
* Keeps old {@link QueryParser#parse(QueryShardContext)} method as a stub delegating to
|
||||
* {@link QueryParser#fromXContent(QueryParseContext)} and {@link QueryBuilder#toQuery(QueryShardContext)}}
|
||||
*/
|
||||
//norelease needs to be removed once we parse search requests on the coordinating node, as the parse method is not needed anymore at that point.
|
||||
public abstract class BaseQueryParser<QB extends QueryBuilder<QB>> implements QueryParser<QB> {
|
||||
|
||||
@Override
|
||||
public final Query parse(QueryShardContext context) throws IOException {
|
||||
return fromXContent(context.parseContext()).toQuery(context);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This class with method impl is an intermediate step in the query parsers refactoring.
|
||||
* Provides a fromXContent default implementation for query parsers that don't have yet a
|
||||
* specific fromXContent implementation that returns a QueryBuilder.
|
||||
*/
|
||||
//norelease to be removed once all queries are moved over to extend BaseQueryParser
|
||||
public abstract class BaseQueryParserTemp implements QueryParser {
|
||||
|
||||
@Override
|
||||
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
Query query = parse(parseContext.shardContext());
|
||||
return new QueryWrappingQueryBuilder(query);
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ import java.util.List;
|
|||
/**
|
||||
* Parser for bool query
|
||||
*/
|
||||
public class BoolQueryParser extends BaseQueryParser<BoolQueryBuilder> {
|
||||
public class BoolQueryParser implements QueryParser<BoolQueryBuilder> {
|
||||
|
||||
@Inject
|
||||
public BoolQueryParser(Settings settings) {
|
||||
|
@ -78,12 +78,12 @@ public class BoolQueryParser extends BaseQueryParser<BoolQueryBuilder> {
|
|||
shouldClauses.add(query);
|
||||
break;
|
||||
case "filter":
|
||||
query = parseContext.parseInnerFilterToQueryBuilder();
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
filterClauses.add(query);
|
||||
break;
|
||||
case "must_not":
|
||||
case "mustNot":
|
||||
query = parseContext.parseInnerFilterToQueryBuilder();
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
mustNotClauses.add(query);
|
||||
break;
|
||||
default:
|
||||
|
@ -101,12 +101,12 @@ public class BoolQueryParser extends BaseQueryParser<BoolQueryBuilder> {
|
|||
shouldClauses.add(query);
|
||||
break;
|
||||
case "filter":
|
||||
query = parseContext.parseInnerFilterToQueryBuilder();
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
filterClauses.add(query);
|
||||
break;
|
||||
case "must_not":
|
||||
case "mustNot":
|
||||
query = parseContext.parseInnerFilterToQueryBuilder();
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
mustNotClauses.add(query);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -28,7 +27,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for boosting query
|
||||
*/
|
||||
public class BoostingQueryParser extends BaseQueryParser<BoostingQueryBuilder> {
|
||||
public class BoostingQueryParser implements QueryParser<BoostingQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for common terms query
|
||||
*/
|
||||
public class CommonTermsQueryParser extends BaseQueryParser<CommonTermsQueryBuilder> {
|
||||
public class CommonTermsQueryParser implements QueryParser<CommonTermsQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for constant_score query
|
||||
*/
|
||||
public class ConstantScoreQueryParser extends BaseQueryParser<ConstantScoreQueryBuilder> {
|
||||
public class ConstantScoreQueryParser implements QueryParser<ConstantScoreQueryBuilder> {
|
||||
|
||||
private static final ParseField INNER_QUERY_FIELD = new ParseField("filter", "query");
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class ConstantScoreQueryParser extends BaseQueryParser<ConstantScoreQuery
|
|||
// skip
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, INNER_QUERY_FIELD)) {
|
||||
query = parseContext.parseInnerFilterToQueryBuilder();
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
queryFound = true;
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[constant_score] query does not support [" + currentFieldName + "]");
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -31,7 +30,7 @@ import java.util.List;
|
|||
/**
|
||||
* Parser for dis_max query
|
||||
*/
|
||||
public class DisMaxQueryParser extends BaseQueryParser<DisMaxQueryBuilder> {
|
||||
public class DisMaxQueryParser implements QueryParser<DisMaxQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -28,7 +27,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for exists query
|
||||
*/
|
||||
public class ExistsQueryParser extends BaseQueryParser<ExistsQueryBuilder> {
|
||||
public class ExistsQueryParser implements QueryParser<ExistsQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -21,14 +21,13 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Parser for field_masking_span query
|
||||
*/
|
||||
public class FieldMaskingSpanQueryParser extends BaseQueryParser<FieldMaskingSpanQueryBuilder> {
|
||||
public class FieldMaskingSpanQueryParser implements QueryParser<FieldMaskingSpanQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -21,14 +21,11 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.support.QueryParsers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FuzzyQueryParser extends BaseQueryParser {
|
||||
public class FuzzyQueryParser implements QueryParser<FuzzyQueryBuilder> {
|
||||
|
||||
private static final ParseField FUZZINESS = Fuzziness.FIELD.withDeprecation("min_similarity");
|
||||
|
||||
|
@ -38,14 +35,14 @@ public class FuzzyQueryParser extends BaseQueryParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
public FuzzyQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
if (token != XContentParser.Token.FIELD_NAME) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[fuzzy] query malformed, no field");
|
||||
}
|
||||
|
||||
|
||||
String fieldName = parser.currentName();
|
||||
Object value = null;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GeoBoundingBoxQueryParser extends BaseQueryParser<GeoBoundingBoxQueryBuilder> {
|
||||
public class GeoBoundingBoxQueryParser implements QueryParser<GeoBoundingBoxQueryBuilder> {
|
||||
|
||||
public static final String NAME = "geo_bbox";
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.io.IOException;
|
|||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class GeoDistanceQueryParser extends BaseQueryParser {
|
||||
public class GeoDistanceQueryParser implements QueryParser<GeoDistanceQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -47,7 +47,7 @@ public class GeoDistanceQueryParser extends BaseQueryParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
public GeoDistanceQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
|
||||
XContentParser.Token token;
|
||||
|
|
|
@ -37,7 +37,7 @@ import java.io.IOException;
|
|||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class GeoDistanceRangeQueryParser extends BaseQueryParser<GeoDistanceRangeQueryBuilder> {
|
||||
public class GeoDistanceRangeQueryParser implements QueryParser<GeoDistanceRangeQueryBuilder> {
|
||||
|
||||
public static final ParseField FROM_FIELD = new ParseField("from");
|
||||
public static final ParseField TO_FIELD = new ParseField("to");
|
||||
|
|
|
@ -115,7 +115,7 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
|||
shell.add(shell.get(0));
|
||||
}
|
||||
|
||||
final boolean indexCreatedBeforeV2_0 = context.parseContext().shardContext().indexVersionCreated().before(Version.V_2_0_0);
|
||||
final boolean indexCreatedBeforeV2_0 = context.indexVersionCreated().before(Version.V_2_0_0);
|
||||
// validation was not available prior to 2.x, so to support bwc
|
||||
// percolation queries we only ignore_malformed on 2.x created indexes
|
||||
if (!indexCreatedBeforeV2_0 && !ignoreMalformed) {
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.common.ParseField;
|
|||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.GeoUtils;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
||||
|
||||
|
@ -43,7 +42,7 @@ import java.util.List;
|
|||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class GeoPolygonQueryParser extends BaseQueryParser<GeoPolygonQueryBuilder> {
|
||||
public class GeoPolygonQueryParser implements QueryParser<GeoPolygonQueryBuilder> {
|
||||
|
||||
public static final ParseField COERCE_FIELD = new ParseField("coerce", "normalize");
|
||||
public static final ParseField IGNORE_MALFORMED_FIELD = new ParseField("ignore_malformed");
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GeoShapeQueryParser extends BaseQueryParser<GeoShapeQueryBuilder> {
|
||||
public class GeoShapeQueryParser implements QueryParser<GeoShapeQueryBuilder> {
|
||||
|
||||
public static final ParseField SHAPE_FIELD = new ParseField("shape");
|
||||
public static final ParseField STRATEGY_FIELD = new ParseField("strategy");
|
||||
|
|
|
@ -266,7 +266,7 @@ public class GeohashCellQuery {
|
|||
}
|
||||
}
|
||||
|
||||
public static class Parser extends BaseQueryParser<Builder> {
|
||||
public static class Parser implements QueryParser<Builder> {
|
||||
|
||||
@Inject
|
||||
public Parser() {
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* A query parser for <tt>has_child</tt> queries.
|
||||
*/
|
||||
public class HasChildQueryParser extends BaseQueryParser {
|
||||
public class HasChildQueryParser implements QueryParser<HasChildQueryBuilder> {
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class HasChildQueryParser extends BaseQueryParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
public HasChildQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||
String childType = null;
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.elasticsearch.index.query.support.QueryInnerHits;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HasParentQueryParser extends BaseQueryParser {
|
||||
public class HasParentQueryParser implements QueryParser<HasParentQueryBuilder> {
|
||||
|
||||
private static final HasParentQueryBuilder PROTOTYPE = new HasParentQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
|
@ -40,7 +40,7 @@ public class HasParentQueryParser extends BaseQueryParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
public HasParentQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
|
||||
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
|||
/**
|
||||
* Parser for ids query
|
||||
*/
|
||||
public class IdsQueryParser extends BaseQueryParser<IdsQueryBuilder> {
|
||||
public class IdsQueryParser implements QueryParser<IdsQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -225,7 +225,7 @@ public class IndexQueryParserService extends AbstractIndexComponent {
|
|||
QueryShardContext context = cache.get();
|
||||
context.reset(parser);
|
||||
try {
|
||||
Query filter = context.parseContext().parseInnerFilter();
|
||||
Query filter = context.parseContext().parseInnerQueryBuilder().toFilter(context);
|
||||
if (filter == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -31,7 +30,7 @@ import java.util.Collection;
|
|||
/**
|
||||
* Parser for {@link IndicesQueryBuilder}.
|
||||
*/
|
||||
public class IndicesQueryParser extends BaseQueryParser {
|
||||
public class IndicesQueryParser implements QueryParser {
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
private static final ParseField NO_MATCH_QUERY = new ParseField("no_match_query", "no_match_filter");
|
||||
|
@ -97,7 +96,7 @@ public class IndicesQueryParser extends BaseQueryParser {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (innerQuery == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[indices] requires 'query' element");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for match_all query
|
||||
*/
|
||||
public class MatchAllQueryParser extends BaseQueryParser<MatchAllQueryBuilder> {
|
||||
public class MatchAllQueryParser implements QueryParser<MatchAllQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -21,12 +21,11 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MatchNoneQueryParser extends BaseQueryParser {
|
||||
public class MatchNoneQueryParser implements QueryParser<MatchNoneQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.apache.lucene.search.FuzzyQuery;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.search.MatchQuery;
|
||||
|
@ -32,7 +31,7 @@ import java.io.IOException;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class MatchQueryParser extends BaseQueryParser {
|
||||
public class MatchQueryParser implements QueryParser<MatchQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for missing query
|
||||
*/
|
||||
public class MissingQueryParser extends BaseQueryParser<MissingQueryBuilder> {
|
||||
public class MissingQueryParser implements QueryParser<MissingQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.util.List;
|
|||
*
|
||||
* The documents are provided as a set of strings and/or a list of {@link Item}.
|
||||
*/
|
||||
public class MoreLikeThisQueryParser extends BaseQueryParser<MoreLikeThisQueryBuilder> {
|
||||
public class MoreLikeThisQueryParser implements QueryParser<MoreLikeThisQueryBuilder> {
|
||||
|
||||
public interface Field {
|
||||
ParseField FIELDS = new ParseField("fields");
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.Map;
|
|||
/**
|
||||
* Same as {@link MatchQueryParser} but has support for multiple fields.
|
||||
*/
|
||||
public class MultiMatchQueryParser extends BaseQueryParser<MultiMatchQueryBuilder> {
|
||||
public class MultiMatchQueryParser implements QueryParser<MultiMatchQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -19,26 +19,15 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.ConstantScoreQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.lucene.search.Queries;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.support.InnerHitsQueryParserHelper;
|
||||
import org.elasticsearch.index.query.support.NestedInnerQueryParseSupport;
|
||||
import org.elasticsearch.index.query.support.QueryInnerHits;
|
||||
import org.elasticsearch.search.fetch.innerhits.InnerHitsContext;
|
||||
import org.elasticsearch.search.fetch.innerhits.InnerHitsSubSearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class NestedQueryParser extends BaseQueryParser<NestedQueryBuilder> {
|
||||
public class NestedQueryParser implements QueryParser<NestedQueryBuilder> {
|
||||
|
||||
private static final ParseField FILTER_FIELD = new ParseField("filter").withAllDeprecated("query");
|
||||
private static final NestedQueryBuilder PROTOTYPE = new NestedQueryBuilder("", EmptyQueryBuilder.PROTOTYPE);
|
||||
|
@ -66,7 +55,7 @@ public class NestedQueryParser extends BaseQueryParser<NestedQueryBuilder> {
|
|||
if ("query".equals(currentFieldName)) {
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FILTER_FIELD)) {
|
||||
query = parseContext.parseInnerFilterToQueryBuilder();
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
} else if ("inner_hits".equals(currentFieldName)) {
|
||||
queryInnerHits = new QueryInnerHits(parser);
|
||||
} else {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for not query
|
||||
*/
|
||||
public class NotQueryParser extends BaseQueryParser<NotQueryBuilder> {
|
||||
public class NotQueryParser implements QueryParser<NotQueryBuilder> {
|
||||
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
|
||||
|
||||
|
@ -56,12 +55,12 @@ public class NotQueryParser extends BaseQueryParser<NotQueryBuilder> {
|
|||
// skip
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
|
||||
query = parseContext.parseInnerFilterToQueryBuilder();
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
queryFound = true;
|
||||
} else {
|
||||
queryFound = true;
|
||||
// its the filter, and the name is the field
|
||||
query = parseContext.parseInnerFilterToQueryBuilder(currentFieldName);
|
||||
query = parseContext.parseInnerQueryBuilderByName(currentFieldName);
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("_name".equals(currentFieldName)) {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for prefix query
|
||||
*/
|
||||
public class PrefixQueryParser extends BaseQueryParser<PrefixQueryBuilder> {
|
||||
public class PrefixQueryParser implements QueryParser<PrefixQueryBuilder> {
|
||||
|
||||
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of prefix query");
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +27,7 @@ import java.io.IOException;
|
|||
*/
|
||||
// TODO: remove when https://github.com/elastic/elasticsearch/issues/13326 is fixed
|
||||
@Deprecated
|
||||
public class QueryFilterParser extends BaseQueryParser<QueryFilterBuilder> {
|
||||
public class QueryFilterParser implements QueryParser<QueryFilterBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
|
@ -60,12 +58,6 @@ public class QueryParseContext {
|
|||
}
|
||||
}
|
||||
|
||||
//norelease this is still used in BaseQueryParserTemp and FunctionScoreQueryParser, remove if not needed there anymore
|
||||
@Deprecated
|
||||
public QueryShardContext shardContext() {
|
||||
return this.shardContext;
|
||||
}
|
||||
|
||||
public XContentParser parser() {
|
||||
return this.parser;
|
||||
}
|
||||
|
@ -81,37 +73,6 @@ public class QueryParseContext {
|
|||
return parseFieldMatcher.match(setting, CACHE) || parseFieldMatcher.match(setting, CACHE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated replaced by calls to parseInnerFilterToQueryBuilder() for the resulting queries
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
//norelease should be possible to remove after refactoring all queries
|
||||
public Query parseInnerFilter() throws QueryShardException, IOException {
|
||||
assert this.shardContext != null;
|
||||
QueryBuilder builder = parseInnerFilterToQueryBuilder();
|
||||
Query result = null;
|
||||
if (builder != null) {
|
||||
result = builder.toQuery(this.shardContext);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated replaced by calls to parseInnerQueryBuilder() for the resulting queries
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
//norelease this method will be removed once all queries are refactored
|
||||
public Query parseInnerQuery() throws IOException, QueryShardException {
|
||||
QueryBuilder builder = parseInnerQueryBuilder();
|
||||
Query result = null;
|
||||
if (builder != null) {
|
||||
result = builder.toQuery(this.shardContext);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new QueryBuilder based on the current state of the parser
|
||||
*/
|
||||
|
@ -139,11 +100,7 @@ public class QueryParseContext {
|
|||
throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, no field after start_object");
|
||||
}
|
||||
|
||||
QueryParser queryParser = queryParser(queryName);
|
||||
if (queryParser == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "No query registered for [" + queryName + "]");
|
||||
}
|
||||
QueryBuilder result = queryParser.fromXContent(this);
|
||||
QueryBuilder result = parseInnerQueryBuilderByName(queryName);
|
||||
if (parser.currentToken() == XContentParser.Token.END_OBJECT || parser.currentToken() == XContentParser.Token.END_ARRAY) {
|
||||
// if we are at END_OBJECT, move to the next one...
|
||||
parser.nextToken();
|
||||
|
@ -151,34 +108,12 @@ public class QueryParseContext {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new QueryBuilder based on the current state of the parser, but does so that the inner query
|
||||
* is parsed to a filter
|
||||
*/
|
||||
//norelease setting and checking the isFilter Flag should completely be moved to toQuery/toFilter after query refactoring
|
||||
public QueryBuilder parseInnerFilterToQueryBuilder() throws IOException {
|
||||
final boolean originalIsFilter = this.shardContext.isFilter;
|
||||
try {
|
||||
this.shardContext.isFilter = true;
|
||||
return parseInnerQueryBuilder();
|
||||
} finally {
|
||||
this.shardContext.isFilter = originalIsFilter;
|
||||
}
|
||||
}
|
||||
|
||||
//norelease setting and checking the isFilter Flag should completely be moved to toQuery/toFilter after query refactoring
|
||||
public QueryBuilder parseInnerFilterToQueryBuilder(String queryName) throws IOException {
|
||||
final boolean originalIsFilter = this.shardContext.isFilter;
|
||||
try {
|
||||
this.shardContext.isFilter = true;
|
||||
QueryParser queryParser = queryParser(queryName);
|
||||
if (queryParser == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "No query registered for [" + queryName + "]");
|
||||
}
|
||||
return queryParser.fromXContent(this);
|
||||
} finally {
|
||||
this.shardContext.isFilter = originalIsFilter;
|
||||
public QueryBuilder parseInnerQueryBuilderByName(String queryName) throws IOException {
|
||||
QueryParser queryParser = queryParser(queryName);
|
||||
if (queryParser == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "No query registered for [" + queryName + "]");
|
||||
}
|
||||
return queryParser.fromXContent(this);
|
||||
}
|
||||
|
||||
public ParseFieldMatcher parseFieldMatcher() {
|
||||
|
@ -189,6 +124,11 @@ public class QueryParseContext {
|
|||
this.parser = innerParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query parser for a specific type of query registered under its name
|
||||
* @param name the name of the parser to retrieve
|
||||
* @return the query parser
|
||||
*/
|
||||
QueryParser queryParser(String name) {
|
||||
return indicesQueriesRegistry.queryParsers().get(name);
|
||||
}
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
@ -35,18 +32,6 @@ public interface QueryParser<QB extends QueryBuilder<QB>> {
|
|||
*/
|
||||
String[] names();
|
||||
|
||||
/**
|
||||
* Parses the into a query from the current parser location. Will be at
|
||||
* "START_OBJECT" location, and should end when the token is at the matching
|
||||
* "END_OBJECT".
|
||||
* <p>
|
||||
* Returns <tt>null</tt> if this query should be ignored in the context of
|
||||
* the DSL.
|
||||
*/
|
||||
//norelease can be removed in favour of fromXContent once search requests can be parsed on the coordinating node
|
||||
@Nullable
|
||||
Query parse(QueryShardContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Creates a new {@link QueryBuilder} from the query held by the {@link QueryShardContext}
|
||||
* in {@link org.elasticsearch.common.xcontent.XContent} format
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.index.query;
|
|||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -34,7 +33,7 @@ import java.util.Map;
|
|||
/**
|
||||
* Parser for query_string query
|
||||
*/
|
||||
public class QueryStringQueryParser extends BaseQueryParser {
|
||||
public class QueryStringQueryParser implements QueryParser {
|
||||
|
||||
private static final ParseField FUZZINESS = Fuzziness.FIELD.withDeprecation("fuzzy_min_sim");
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* QueryBuilder implementation that holds a lucene query, which can be returned by {@link QueryBuilder#toQuery(QueryShardContext)}.
|
||||
* Doesn't support conversion to {@link org.elasticsearch.common.xcontent.XContent} via {@link #doXContent(XContentBuilder, Params)}.
|
||||
*/
|
||||
//norelease to be removed once all queries support separate fromXContent and toQuery methods. Make AbstractQueryBuilder#toQuery final as well then.
|
||||
public class QueryWrappingQueryBuilder extends AbstractQueryBuilder<QueryWrappingQueryBuilder> implements SpanQueryBuilder<QueryWrappingQueryBuilder>, MultiTermQueryBuilder<QueryWrappingQueryBuilder>{
|
||||
|
||||
private Query query;
|
||||
|
||||
public QueryWrappingQueryBuilder(Query query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query doToQuery(QueryShardContext context) throws IOException {
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
// this should not be called since we overwrite BaseQueryBuilder#toQuery() in this class
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setFinalBoost(Query query) {
|
||||
//no-op the wrapper lucene query has already its boost set
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for range query
|
||||
*/
|
||||
public class RangeQueryParser extends BaseQueryParser<RangeQueryBuilder> {
|
||||
public class RangeQueryParser implements QueryParser<RangeQueryBuilder> {
|
||||
|
||||
private static final ParseField FIELDDATA_FIELD = new ParseField("fielddata").withAllDeprecated("[no replacement]");
|
||||
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of range query");
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for regexp query
|
||||
*/
|
||||
public class RegexpQueryParser extends BaseQueryParser<RegexpQueryBuilder> {
|
||||
public class RegexpQueryParser implements QueryParser<RegexpQueryBuilder> {
|
||||
|
||||
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of regexp query");
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Script.ScriptField;
|
||||
|
@ -34,7 +33,7 @@ import java.util.Map;
|
|||
/**
|
||||
* Parser for script query
|
||||
*/
|
||||
public class ScriptQueryParser extends BaseQueryParser<ScriptQueryBuilder> {
|
||||
public class ScriptQueryParser implements QueryParser<ScriptQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
@ -45,7 +44,7 @@ public class ScriptQueryParser extends BaseQueryParser<ScriptQueryBuilder> {
|
|||
public ScriptQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
ScriptParameterParser scriptParameterParser = new ScriptParameterParser();
|
||||
|
||||
|
||||
// also, when caching, since its isCacheable is false, will result in loading all bit set...
|
||||
Script script = null;
|
||||
Map<String, Object> params = null;
|
||||
|
|
|
@ -19,10 +19,8 @@
|
|||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -60,7 +58,7 @@ import java.util.Map;
|
|||
* {@code fields} - fields to search, defaults to _all if not set, allows
|
||||
* boosting a field with ^n
|
||||
*/
|
||||
public class SimpleQueryStringParser extends BaseQueryParser<SimpleQueryStringBuilder> {
|
||||
public class SimpleQueryStringParser implements QueryParser<SimpleQueryStringBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for span_containing query
|
||||
*/
|
||||
public class SpanContainingQueryParser extends BaseQueryParser<SpanContainingQueryBuilder> {
|
||||
public class SpanContainingQueryParser implements QueryParser<SpanContainingQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for span_first query
|
||||
*/
|
||||
public class SpanFirstQueryParser extends BaseQueryParser<SpanFirstQueryBuilder> {
|
||||
public class SpanFirstQueryParser implements QueryParser<SpanFirstQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -28,7 +27,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for span_multi query
|
||||
*/
|
||||
public class SpanMultiTermQueryParser extends BaseQueryParser<SpanMultiTermQueryBuilder> {
|
||||
public class SpanMultiTermQueryParser implements QueryParser<SpanMultiTermQueryBuilder> {
|
||||
|
||||
public static final String MATCH_NAME = "match";
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
|||
/**
|
||||
* Parser for span_near query
|
||||
*/
|
||||
public class SpanNearQueryParser extends BaseQueryParser<SpanNearQueryBuilder> {
|
||||
public class SpanNearQueryParser implements QueryParser<SpanNearQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for span_not query
|
||||
*/
|
||||
public class SpanNotQueryParser extends BaseQueryParser<SpanNotQueryBuilder> {
|
||||
public class SpanNotQueryParser implements QueryParser<SpanNotQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
|||
/**
|
||||
* Parser for span_or query
|
||||
*/
|
||||
public class SpanOrQueryParser extends BaseQueryParser<SpanOrQueryBuilder> {
|
||||
public class SpanOrQueryParser implements QueryParser<SpanOrQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for span_term query
|
||||
*/
|
||||
public class SpanTermQueryParser extends BaseQueryParser<SpanTermQueryBuilder> {
|
||||
public class SpanTermQueryParser implements QueryParser<SpanTermQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for span_within query
|
||||
*/
|
||||
public class SpanWithinQueryParser extends BaseQueryParser<SpanWithinQueryBuilder> {
|
||||
public class SpanWithinQueryParser implements QueryParser<SpanWithinQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.Template;
|
||||
|
@ -33,7 +32,7 @@ import java.util.Map;
|
|||
* In the simplest case, parse template string and variables from the request,
|
||||
* compile the template and execute the template against the given variables.
|
||||
* */
|
||||
public class TemplateQueryParser extends BaseQueryParser<TemplateQueryBuilder> {
|
||||
public class TemplateQueryParser implements QueryParser<TemplateQueryBuilder> {
|
||||
|
||||
private final static Map<String, ScriptService.ScriptType> parametersToTypes = new HashMap<>();
|
||||
static {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for the term query
|
||||
*/
|
||||
public class TermQueryParser extends BaseQueryParser<TermQueryBuilder> {
|
||||
public class TermQueryParser implements QueryParser<TermQueryBuilder> {
|
||||
|
||||
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of term query");
|
||||
private static final ParseField BOOST_FIELD = new ParseField("boost").withAllDeprecated("boost is not supported in short version of term query");
|
||||
|
|
|
@ -36,7 +36,7 @@ import java.util.List;
|
|||
* It also supports a terms lookup mechanism which can be used to fetch the term values from
|
||||
* a document in an index.
|
||||
*/
|
||||
public class TermsQueryParser extends BaseQueryParser {
|
||||
public class TermsQueryParser implements QueryParser {
|
||||
|
||||
private static final ParseField MIN_SHOULD_MATCH_FIELD = new ParseField("min_match", "min_should_match", "minimum_should_match")
|
||||
.withAllDeprecated("Use [bool] query instead");
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.query;
|
|||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,7 +28,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for type query
|
||||
*/
|
||||
public class TypeQueryParser extends BaseQueryParser<TypeQueryBuilder> {
|
||||
public class TypeQueryParser implements QueryParser<TypeQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -28,7 +27,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Parser for wildcard query
|
||||
*/
|
||||
public class WildcardQueryParser extends BaseQueryParser<WildcardQueryBuilder> {
|
||||
public class WildcardQueryParser implements QueryParser<WildcardQueryBuilder> {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -28,7 +27,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Query parser for JSON Queries.
|
||||
*/
|
||||
public class WrapperQueryParser extends BaseQueryParser {
|
||||
public class WrapperQueryParser implements QueryParser {
|
||||
|
||||
@Override
|
||||
public String[] names() {
|
||||
|
|
|
@ -38,7 +38,7 @@ import java.util.List;
|
|||
/**
|
||||
* Parser for function_score query
|
||||
*/
|
||||
public class FunctionScoreQueryParser extends BaseQueryParser<FunctionScoreQueryBuilder> {
|
||||
public class FunctionScoreQueryParser implements QueryParser<FunctionScoreQueryBuilder> {
|
||||
|
||||
private static final FunctionScoreQueryBuilder PROTOTYPE = new FunctionScoreQueryBuilder(EmptyQueryBuilder.PROTOTYPE, new FunctionScoreQueryBuilder.FilterFunctionBuilder[0]);
|
||||
|
||||
|
@ -88,7 +88,7 @@ public class FunctionScoreQueryParser extends BaseQueryParser<FunctionScoreQuery
|
|||
} else if ("query".equals(currentFieldName)) {
|
||||
query = parseContext.parseInnerQueryBuilder();
|
||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FILTER_FIELD)) {
|
||||
filter = parseContext.parseInnerFilterToQueryBuilder();
|
||||
filter = parseContext.parseInnerQueryBuilder();
|
||||
} else if ("score_mode".equals(currentFieldName) || "scoreMode".equals(currentFieldName)) {
|
||||
scoreMode = FiltersFunctionScoreQuery.ScoreMode.fromString(parser.text());
|
||||
} else if ("boost_mode".equals(currentFieldName) || "boostMode".equals(currentFieldName)) {
|
||||
|
@ -179,7 +179,7 @@ public class FunctionScoreQueryParser extends BaseQueryParser<FunctionScoreQuery
|
|||
functionWeight = parser.floatValue();
|
||||
} else {
|
||||
if ("filter".equals(currentFieldName)) {
|
||||
filter = parseContext.parseInnerFilterToQueryBuilder();
|
||||
filter = parseContext.parseInnerQueryBuilder();
|
||||
} else {
|
||||
if (scoreFunction != null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "failed to parse function_score functions. already found [{}], now encountering [{}].", scoreFunction.getName(), currentFieldName);
|
||||
|
|
|
@ -77,7 +77,7 @@ public class NestedInnerQueryParseSupport {
|
|||
if (path != null) {
|
||||
setPathLevel();
|
||||
try {
|
||||
innerQuery = parseContext.parseInnerQuery();
|
||||
innerQuery = parseContext.parseInnerQueryBuilder().toQuery(this.shardContext);
|
||||
} finally {
|
||||
resetPathLevel();
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class NestedInnerQueryParseSupport {
|
|||
if (path != null) {
|
||||
setPathLevel();
|
||||
try {
|
||||
innerFilter = parseContext.parseInnerFilter();
|
||||
innerFilter = parseContext.parseInnerQueryBuilder().toFilter(this.shardContext);
|
||||
} finally {
|
||||
resetPathLevel();
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class NestedInnerQueryParseSupport {
|
|||
parseContext.parser(innerParser);
|
||||
setPathLevel();
|
||||
try {
|
||||
innerQuery = parseContext.parseInnerQuery();
|
||||
innerQuery = parseContext.parseInnerQueryBuilder().toQuery(this.shardContext);
|
||||
} finally {
|
||||
resetPathLevel();
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class NestedInnerQueryParseSupport {
|
|||
try {
|
||||
XContentParser innerParser = XContentHelper.createParser(source);
|
||||
parseContext.parser(innerParser);
|
||||
innerFilter = parseContext.parseInnerFilter();
|
||||
innerFilter = parseContext.parseInnerQueryBuilder().toFilter(this.shardContext);
|
||||
filterParsed = true;
|
||||
return innerFilter;
|
||||
} finally {
|
||||
|
|
|
@ -56,8 +56,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
/**
|
||||
|
@ -131,7 +129,7 @@ public class TemplateQueryParserTests extends ESTestCase {
|
|||
templateSourceParser.nextToken();
|
||||
|
||||
TemplateQueryParser parser = injector.getInstance(TemplateQueryParser.class);
|
||||
Query query = parser.parse(context);
|
||||
Query query = parser.fromXContent(context.parseContext()).toQuery(context);
|
||||
assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery);
|
||||
}
|
||||
|
||||
|
@ -143,7 +141,7 @@ public class TemplateQueryParserTests extends ESTestCase {
|
|||
context.reset(templateSourceParser);
|
||||
|
||||
TemplateQueryParser parser = injector.getInstance(TemplateQueryParser.class);
|
||||
Query query = parser.parse(context);
|
||||
Query query = parser.fromXContent(context.parseContext()).toQuery(context);
|
||||
assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery);
|
||||
}
|
||||
|
||||
|
@ -161,7 +159,7 @@ public class TemplateQueryParserTests extends ESTestCase {
|
|||
context.reset(templateSourceParser);
|
||||
|
||||
TemplateQueryParser parser = injector.getInstance(TemplateQueryParser.class);
|
||||
parser.parse(context);
|
||||
parser.fromXContent(context.parseContext()).toQuery(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -173,7 +171,7 @@ public class TemplateQueryParserTests extends ESTestCase {
|
|||
templateSourceParser.nextToken();
|
||||
|
||||
TemplateQueryParser parser = injector.getInstance(TemplateQueryParser.class);
|
||||
Query query = parser.parse(context);
|
||||
Query query = parser.fromXContent(context.parseContext()).toQuery(context);
|
||||
assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,14 +66,14 @@ public class DummyQueryParserPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
public static class DummyQueryParser extends BaseQueryParser {
|
||||
public static class DummyQueryParser implements QueryParser<DummyQueryBuilder> {
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{DummyQueryBuilder.NAME};
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
public DummyQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser.Token token = parseContext.parser().nextToken();
|
||||
assert token == XContentParser.Token.END_OBJECT;
|
||||
return new DummyQueryBuilder();
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.indices;
|
||||
|
||||
import org.apache.lucene.analysis.hunspell.Dictionary;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.inject.ModuleTestCase;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.*;
|
||||
|
@ -42,11 +41,6 @@ public class IndicesModuleTests extends ModuleTestCase {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query parse(QueryShardContext context) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryBuilder getBuilderPrototype() {
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue