diff --git a/core/src/main/java/org/elasticsearch/index/search/stats/StatsGroupsParseElement.java b/core/src/main/java/org/elasticsearch/index/search/stats/StatsGroupsParseElement.java deleted file mode 100644 index f4dcebd9d54..00000000000 --- a/core/src/main/java/org/elasticsearch/index/search/stats/StatsGroupsParseElement.java +++ /dev/null @@ -1,47 +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.search.stats; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - */ -public class StatsGroupsParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token.isValue()) { - context.groupStats(Collections.singletonList(parser.text())); - } else if (token == XContentParser.Token.START_ARRAY) { - List groupStats = new ArrayList<>(4); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - groupStats.add(parser.text()); - } - context.groupStats(groupStats); - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index e0a6ccd09b4..6fe4913d074 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -95,8 +95,6 @@ import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder; import org.elasticsearch.index.query.functionscore.WeightBuilder; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.search.action.SearchTransportService; -import org.elasticsearch.search.aggregations.AggregationBinaryParseElement; -import org.elasticsearch.search.aggregations.AggregationParseElement; import org.elasticsearch.search.aggregations.AggregationPhase; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorBuilder; @@ -375,7 +373,7 @@ public class SearchModule extends AbstractModule { /** * Register a {@link SignificanceHeuristic}. - * + * * @param heuristicName the name(s) at which the heuristic is parsed and streamed. The {@link ParseField#getPreferredName()} is the name * under which it is streamed. All names work for the parser. * @param reader reads the heuristic from a stream @@ -557,11 +555,8 @@ public class SearchModule extends AbstractModule { registerPipelineAggregation(SerialDiffPipelineAggregatorBuilder::new, SerialDiffPipelineAggregatorBuilder::parse, SerialDiffPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); - AggregationParseElement aggParseElement = new AggregationParseElement(aggregatorParsers, queryParserRegistry); - AggregationBinaryParseElement aggBinaryParseElement = new AggregationBinaryParseElement(aggregatorParsers, queryParserRegistry); - AggregationPhase aggPhase = new AggregationPhase(aggParseElement, aggBinaryParseElement); + AggregationPhase aggPhase = new AggregationPhase(); bind(AggregatorParsers.class).toInstance(aggregatorParsers); - bind(AggregationParseElement.class).toInstance(aggParseElement); bind(AggregationPhase.class).toInstance(aggPhase); } diff --git a/core/src/main/java/org/elasticsearch/search/SearchPhase.java b/core/src/main/java/org/elasticsearch/search/SearchPhase.java index 85a75b9738d..48c041f12f5 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchPhase.java +++ b/core/src/main/java/org/elasticsearch/search/SearchPhase.java @@ -21,6 +21,7 @@ package org.elasticsearch.search; import org.elasticsearch.search.internal.SearchContext; +import java.util.Collections; import java.util.Map; /** @@ -28,7 +29,9 @@ import java.util.Map; */ public interface SearchPhase { - Map parseElements(); + default Map parseElements() { + return Collections.emptyMap(); + } /** * Performs pre processing of the search context before the execute. diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index 636e4338063..4cf440f0a95 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -63,7 +63,6 @@ import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.InnerHitBuilder; -import org.elasticsearch.index.search.stats.StatsGroupsParseElement; import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.SearchOperationListener; @@ -186,7 +185,6 @@ public class SearchService extends AbstractLifecycleComponent imp elementParsers.putAll(dfsPhase.parseElements()); elementParsers.putAll(queryPhase.parseElements()); elementParsers.putAll(fetchPhase.parseElements()); - elementParsers.put("stats", new StatsGroupsParseElement()); this.elementParsers = unmodifiableMap(elementParsers); this.keepAliveReaper = threadPool.scheduleWithFixedDelay(new Reaper(), keepAliveInterval); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationBinaryParseElement.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationBinaryParseElement.java deleted file mode 100644 index d1fd5b137aa..00000000000 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationBinaryParseElement.java +++ /dev/null @@ -1,45 +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.search.aggregations; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.indices.query.IndicesQueriesRegistry; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class AggregationBinaryParseElement extends AggregationParseElement { - - @Inject - public AggregationBinaryParseElement(AggregatorParsers aggregatorParsers, IndicesQueriesRegistry queriesRegistry) { - super(aggregatorParsers, queriesRegistry); - } - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - byte[] aggSource = parser.binaryValue(); - try (XContentParser aSourceParser = XContentFactory.xContent(aggSource).createParser(aggSource)) { - aSourceParser.nextToken(); // move past the first START_OBJECT - super.parse(aSourceParser, context); - } - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationParseElement.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationParseElement.java deleted file mode 100644 index 2c94fc45ffc..00000000000 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationParseElement.java +++ /dev/null @@ -1,72 +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.search.aggregations; - -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.query.QueryParseContext; -import org.elasticsearch.indices.query.IndicesQueriesRegistry; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.internal.SearchContext; - -/** - * The search parse element that is responsible for parsing the get part of the request. - * - * For example (in bold): - *
- *      curl -XGET 'localhost:9200/_search?search_type=count' -d '{
- *          query: {
- *              match_all : {}
- *          },
- *          addAggregation : {
- *              avg_price: {
- *                  avg : { field : price }
- *              },
- *              categories: {
- *                  terms : { field : category, size : 12 },
- *                  addAggregation: {
- *                      avg_price : { avg : { field : price }}
- *                  }
- *              }
- *          }
- *      }'
- * 
- */ -public class AggregationParseElement implements SearchParseElement { - - private final AggregatorParsers aggregatorParsers; - private IndicesQueriesRegistry queriesRegistry; - - @Inject - public AggregationParseElement(AggregatorParsers aggregatorParsers, IndicesQueriesRegistry queriesRegistry) { - this.aggregatorParsers = aggregatorParsers; - this.queriesRegistry = queriesRegistry; - } - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, context.parseFieldMatcher()); - AggregatorFactories.Builder builders = aggregatorParsers.parseAggregators(parseContext); - AggregationContext aggContext = new AggregationContext(context); - AggregatorFactories factories = builders.build(aggContext, null); - factories.validate(); - context.aggregations(new SearchContextAggregations(factories)); - } -} diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java index 4c17a23c8fa..4953a39d4b5 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java @@ -24,7 +24,6 @@ import org.apache.lucene.search.Collector; import org.apache.lucene.search.Query; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; @@ -38,33 +37,15 @@ import org.elasticsearch.search.query.QueryPhaseExecutionException; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import static java.util.Collections.unmodifiableMap; /** * */ public class AggregationPhase implements SearchPhase { - private final Map parseElements; @Inject - public AggregationPhase(AggregationParseElement parseElement, AggregationBinaryParseElement binaryParseElement) { - Map parseElements = new HashMap<>(); - parseElements.put("aggregations", parseElement); - parseElements.put("aggs", parseElement); - parseElements.put("aggregations_binary", binaryParseElement); - parseElements.put("aggregationsBinary", binaryParseElement); - parseElements.put("aggs_binary", binaryParseElement); - parseElements.put("aggsBinary", binaryParseElement); - this.parseElements = unmodifiableMap(parseElements); - } - - @Override - public Map parseElements() { - return parseElements; + public AggregationPhase() { } @Override diff --git a/core/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java b/core/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java index fab8323d04d..de06655f414 100644 --- a/core/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java +++ b/core/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java @@ -28,7 +28,6 @@ import org.apache.lucene.index.TermContext; import org.apache.lucene.search.CollectionStatistics; import org.apache.lucene.search.TermStatistics; import org.elasticsearch.common.collect.HppcMaps; -import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.rescore.RescoreSearchContext; @@ -36,20 +35,12 @@ import org.elasticsearch.search.rescore.RescoreSearchContext; import java.util.AbstractSet; import java.util.Collection; import java.util.Iterator; -import java.util.Map; - -import static java.util.Collections.emptyMap; /** * */ public class DfsPhase implements SearchPhase { - @Override - public Map parseElements() { - return emptyMap(); - } - @Override public void preProcess(SearchContext context) { } diff --git a/core/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java index 5019bab9128..32326aa1579 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java @@ -83,7 +83,6 @@ public class FetchPhase implements SearchPhase { @Override public Map parseElements() { Map parseElements = new HashMap<>(); - parseElements.put("fields", new FieldsParseElement()); for (FetchSubPhase fetchSubPhase : fetchSubPhases) { parseElements.putAll(fetchSubPhase.parseElements()); } diff --git a/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhase.java index b6a25d9db11..58d6ff36a2f 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/FetchSubPhase.java @@ -27,6 +27,7 @@ import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.SearchContext; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -101,7 +102,9 @@ public interface FetchSubPhase { } - Map parseElements(); + default Map parseElements() { + return Collections.emptyMap(); + } boolean hitExecutionNeeded(SearchContext context); diff --git a/core/src/main/java/org/elasticsearch/search/fetch/FieldsParseElement.java b/core/src/main/java/org/elasticsearch/search/fetch/FieldsParseElement.java deleted file mode 100644 index 74a37c7e8be..00000000000 --- a/core/src/main/java/org/elasticsearch/search/fetch/FieldsParseElement.java +++ /dev/null @@ -1,50 +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.search.fetch; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class FieldsParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token == XContentParser.Token.START_ARRAY) { - boolean added = false; - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - String name = parser.text(); - added = true; - context.fieldNames().add(name); - } - if (!added) { - context.emptyFieldNames(); - } - } else if (token == XContentParser.Token.VALUE_STRING) { - String name = parser.text(); - context.fieldNames().add(name); - - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/fetch/explain/ExplainFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/explain/ExplainFetchSubPhase.java index 42eecb58820..0d8b4ef3271 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/explain/ExplainFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/explain/ExplainFetchSubPhase.java @@ -19,7 +19,6 @@ package org.elasticsearch.search.fetch.explain; import org.apache.lucene.search.Explanation; -import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.fetch.FetchPhaseExecutionException; import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.search.internal.InternalSearchHit; @@ -27,20 +26,12 @@ import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.rescore.RescoreSearchContext; import java.io.IOException; -import java.util.Map; - -import static java.util.Collections.singletonMap; /** * */ public class ExplainFetchSubPhase implements FetchSubPhase { - @Override - public Map parseElements() { - return singletonMap("explain", new ExplainParseElement()); - } - @Override public boolean hitsExecutionNeeded(SearchContext context) { return false; diff --git a/core/src/main/java/org/elasticsearch/search/fetch/explain/ExplainParseElement.java b/core/src/main/java/org/elasticsearch/search/fetch/explain/ExplainParseElement.java deleted file mode 100644 index 7d44a9d0f01..00000000000 --- a/core/src/main/java/org/elasticsearch/search/fetch/explain/ExplainParseElement.java +++ /dev/null @@ -1,38 +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.search.fetch.explain; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class ExplainParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token.isValue()) { - context.explain(parser.booleanValue()); - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsFetchSubPhase.java index 16b1311809c..f8034719a1d 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsFetchSubPhase.java @@ -23,7 +23,6 @@ import org.elasticsearch.index.fielddata.AtomicFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.search.SearchHitField; -import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHitField; @@ -31,9 +30,6 @@ import org.elasticsearch.search.internal.SearchContext; import java.util.ArrayList; import java.util.HashMap; -import java.util.Map; - -import static java.util.Collections.unmodifiableMap; /** * Query sub phase which pulls data from field data (using the cache if @@ -61,14 +57,6 @@ public class FieldDataFieldsFetchSubPhase implements FetchSubPhase { public FieldDataFieldsFetchSubPhase() { } - @Override - public Map parseElements() { - Map parseElements = new HashMap<>(); - parseElements.put("fielddata_fields", new FieldDataFieldsParseElement()); - parseElements.put("fielddataFields", new FieldDataFieldsParseElement()); - return unmodifiableMap(parseElements); - } - @Override public boolean hitsExecutionNeeded(SearchContext context) { return false; diff --git a/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsParseElement.java b/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsParseElement.java deleted file mode 100644 index 4f746c47ec6..00000000000 --- a/core/src/main/java/org/elasticsearch/search/fetch/fielddata/FieldDataFieldsParseElement.java +++ /dev/null @@ -1,58 +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.search.fetch.fielddata; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.fetch.FetchSubPhase; -import org.elasticsearch.search.fetch.FetchSubPhaseParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * Parses field name values from the {@code fielddata_fields} parameter in a - * search request. - *
- * {
- *   "query": {...},
- *   "fielddata_fields" : ["field1", "field2"]
- * }
- * 
- */ -public class FieldDataFieldsParseElement extends FetchSubPhaseParseElement { - - @Override - protected void innerParse(XContentParser parser, FieldDataFieldsContext fieldDataFieldsContext, SearchContext searchContext) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token == XContentParser.Token.START_ARRAY) { - while (parser.nextToken() != XContentParser.Token.END_ARRAY) { - String fieldName = parser.text(); - fieldDataFieldsContext.add(new FieldDataFieldsContext.FieldDataField(fieldName)); - } - } else if (token == XContentParser.Token.VALUE_STRING) { - String fieldName = parser.text(); - fieldDataFieldsContext.add(new FieldDataFieldsContext.FieldDataField(fieldName)); - } else { - throw new IllegalStateException("Expected either a VALUE_STRING or an START_ARRAY but got " + token); - } - } - - @Override - protected FetchSubPhase.ContextFactory getContextFactory() { - return FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY; - } -} diff --git a/core/src/main/java/org/elasticsearch/search/fetch/innerhits/InnerHitsFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/innerhits/InnerHitsFetchSubPhase.java index 82c3755cdc9..993d1ccbb5b 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/innerhits/InnerHitsFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/innerhits/InnerHitsFetchSubPhase.java @@ -28,9 +28,6 @@ import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.fetch.FetchPhase; import org.elasticsearch.search.fetch.FetchSearchResult; import org.elasticsearch.search.fetch.FetchSubPhase; -import org.elasticsearch.search.fetch.fielddata.FieldDataFieldsParseElement; -import org.elasticsearch.search.fetch.script.ScriptFieldsParseElement; -import org.elasticsearch.search.fetch.source.FetchSourceParseElement; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHits; import org.elasticsearch.search.internal.SearchContext; diff --git a/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsFetchSubPhase.java index 8abcdfb54d6..540ce9aa66b 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsFetchSubPhase.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.fetch.script; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.search.SearchHitField; -import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHitField; @@ -32,26 +31,11 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map; - -import static java.util.Collections.unmodifiableMap; /** * */ public class ScriptFieldsFetchSubPhase implements FetchSubPhase { - private static final Map PARSE_ELEMENTS; - static { - Map parseElements = new HashMap<>(); - parseElements.put("script_fields", new ScriptFieldsParseElement()); - parseElements.put("scriptFields", new ScriptFieldsParseElement()); - PARSE_ELEMENTS = unmodifiableMap(parseElements); - } - - @Override - public Map parseElements() { - return PARSE_ELEMENTS; - } @Override public boolean hitsExecutionNeeded(SearchContext context) { diff --git a/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsParseElement.java b/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsParseElement.java deleted file mode 100644 index 408bf166e15..00000000000 --- a/core/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsParseElement.java +++ /dev/null @@ -1,107 +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.search.fetch.script; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.script.Script; -import org.elasticsearch.script.Script.ScriptField; -import org.elasticsearch.script.ScriptContext; -import org.elasticsearch.script.ScriptParameterParser; -import org.elasticsearch.script.ScriptParameterParser.ScriptParameterValue; -import org.elasticsearch.script.SearchScript; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.SearchParseException; -import org.elasticsearch.search.internal.SearchContext; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - *
- * "script_fields" : {
- *  "test1" : {
- *      "script" : "doc['field_name'].value"
- *  },
- *  "test2" : {
- *      "script" : "..."
- *  }
- * }
- * 
- * - * - */ -public class ScriptFieldsParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token; - String currentFieldName = null; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.START_OBJECT) { - String fieldName = currentFieldName; - ScriptParameterParser scriptParameterParser = new ScriptParameterParser(); - Script script = null; - Map params = null; - boolean ignoreException = false; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if ("params".equals(currentFieldName)) { - params = parser.map(); - } - } else if (token.isValue()) { - if ("ignore_failure".equals(currentFieldName)) { - ignoreException = parser.booleanValue(); - } else { - scriptParameterParser.token(currentFieldName, token, parser, context.parseFieldMatcher()); - } - } - } - - if (script == null) { // Didn't find anything using the new API so try using the old one instead - ScriptParameterValue scriptValue = scriptParameterParser.getDefaultScriptParameterValue(); - if (scriptValue != null) { - if (params == null) { - params = new HashMap<>(); - } - script = new Script(scriptValue.script(), scriptValue.scriptType(), scriptParameterParser.lang(), params); - } - } else if (params != null) { - throw new SearchParseException(context, "script params must be specified inside script object", - parser.getTokenLocation()); - } - - if (script == null) { - throw new SearchParseException(context, "must specify a script in script fields", parser.getTokenLocation()); - } - - SearchScript searchScript = context.scriptService().search(context.lookup(), script, ScriptContext.Standard.SEARCH, - Collections.emptyMap(), context.getQueryShardContext().getClusterState()); - context.scriptFields().add(new ScriptFieldsContext.ScriptField(fieldName, searchScript, ignoreException)); - } - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceParseElement.java b/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceParseElement.java deleted file mode 100644 index 3eb212fb250..00000000000 --- a/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceParseElement.java +++ /dev/null @@ -1,97 +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.search.fetch.source; - -import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - *
- * "source" : true/false
- * "source" : "field"
- * "source" : [ "include", "include" ]
- * "source" : {
- *     "include" : ["obj"]
- *     "exclude" : ["obj"]
- * }
- * 
- */ -public class FetchSourceParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - context.fetchSourceContext(parse(parser)); - } - - public FetchSourceContext parse(XContentParser parser) throws IOException { - XContentParser.Token token; - - List includes = null, excludes = null; - String currentFieldName = null; - token = parser.currentToken(); // we get it on the value - if (parser.isBooleanValue()) { - return new FetchSourceContext(parser.booleanValue()); - } else if (token == XContentParser.Token.VALUE_STRING) { - return new FetchSourceContext(new String[]{parser.text()}); - } else if (token == XContentParser.Token.START_ARRAY) { - includes = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - includes.add(parser.text()); - } - } else if (token == XContentParser.Token.START_OBJECT) { - - List currentList = null; - - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - if ("includes".equals(currentFieldName) || "include".equals(currentFieldName)) { - currentList = includes != null ? includes : (includes = new ArrayList<>(2)); - } else if ("excludes".equals(currentFieldName) || "exclude".equals(currentFieldName)) { - currentList = excludes != null ? excludes : (excludes = new ArrayList<>(2)); - } else { - throw new ElasticsearchParseException("source definition may not contain [{}]", parser.text()); - } - } else if (token == XContentParser.Token.START_ARRAY) { - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - currentList.add(parser.text()); - } - } else if (token.isValue()) { - currentList.add(parser.text()); - } else { - throw new ElasticsearchParseException("unexpected token while parsing source settings"); - } - } - } else { - throw new ElasticsearchParseException("source element value can be of type [{}]", token.name()); - } - - return new FetchSourceContext( - includes == null ? Strings.EMPTY_ARRAY : includes.toArray(new String[includes.size()]), - excludes == null ? Strings.EMPTY_ARRAY : excludes.toArray(new String[excludes.size()])); - } -} diff --git a/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceSubPhase.java index 1ed47383bd0..30220d12694 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceSubPhase.java @@ -22,26 +22,16 @@ package org.elasticsearch.search.fetch.source; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.lookup.SourceLookup; import java.io.IOException; -import java.util.Map; - -import static java.util.Collections.singletonMap; /** */ public class FetchSourceSubPhase implements FetchSubPhase { - private static final Map PARSE_ELEMENTS = singletonMap("_source", new FetchSourceParseElement()); - - @Override - public Map parseElements() { - return PARSE_ELEMENTS; - } @Override public boolean hitsExecutionNeeded(SearchContext context) { diff --git a/core/src/main/java/org/elasticsearch/search/fetch/version/VersionFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/version/VersionFetchSubPhase.java index ec36b7895c7..c5511352ec2 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/version/VersionFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/version/VersionFetchSubPhase.java @@ -24,26 +24,16 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.mapper.internal.UidFieldMapper; -import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.SearchContext; import java.io.IOException; -import java.util.Map; - -import static java.util.Collections.singletonMap; /** * */ public class VersionFetchSubPhase implements FetchSubPhase { - private static final Map PARSE_ELEMENTS = singletonMap("version", new VersionParseElement()); - - @Override - public Map parseElements() { - return PARSE_ELEMENTS; - } @Override public boolean hitsExecutionNeeded(SearchContext context) { diff --git a/core/src/main/java/org/elasticsearch/search/fetch/version/VersionParseElement.java b/core/src/main/java/org/elasticsearch/search/fetch/version/VersionParseElement.java deleted file mode 100644 index bbcf967e1e1..00000000000 --- a/core/src/main/java/org/elasticsearch/search/fetch/version/VersionParseElement.java +++ /dev/null @@ -1,37 +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.search.fetch.version; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class VersionParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token.isValue()) { - context.version(parser.booleanValue()); - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/query/FromParseElement.java b/core/src/main/java/org/elasticsearch/search/query/FromParseElement.java deleted file mode 100644 index 21063a93d35..00000000000 --- a/core/src/main/java/org/elasticsearch/search/query/FromParseElement.java +++ /dev/null @@ -1,44 +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.search.query; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.SearchParseException; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class FromParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token.isValue()) { - int from = parser.intValue(); - if (from < 0) { - throw new SearchParseException(context, "from is set to [" + from + "] and is expected to be higher or equal to 0", - parser.getTokenLocation()); - } - context.from(from); - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/query/IndicesBoostParseElement.java b/core/src/main/java/org/elasticsearch/search/query/IndicesBoostParseElement.java deleted file mode 100644 index eeb70ebe805..00000000000 --- a/core/src/main/java/org/elasticsearch/search/query/IndicesBoostParseElement.java +++ /dev/null @@ -1,54 +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.search.query; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - *
- * {
- *    indicesBoost : {
- *         "index1" : 1.4,
- *         "index2" : 1.5
- *    }
- * }
- * 
- * - * - */ -public class IndicesBoostParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - String indexName = parser.currentName(); - if (indexName.equals(context.shardTarget().index())) { - parser.nextToken(); // move to the value - // we found our query boost - context.queryBoost(parser.floatValue()); - } - } - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/query/MinScoreParseElement.java b/core/src/main/java/org/elasticsearch/search/query/MinScoreParseElement.java deleted file mode 100644 index 49048717cdc..00000000000 --- a/core/src/main/java/org/elasticsearch/search/query/MinScoreParseElement.java +++ /dev/null @@ -1,38 +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.search.query; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class MinScoreParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token.isValue()) { - context.minimumScore(parser.floatValue()); - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/query/PostFilterParseElement.java b/core/src/main/java/org/elasticsearch/search/query/PostFilterParseElement.java deleted file mode 100644 index 1b9fee22d76..00000000000 --- a/core/src/main/java/org/elasticsearch/search/query/PostFilterParseElement.java +++ /dev/null @@ -1,40 +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.search.query; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.query.ParsedQuery; -import org.elasticsearch.index.query.QueryShardContext; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class PostFilterParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - QueryShardContext shardContext = context.getQueryShardContext(); - ParsedQuery postFilter = shardContext.toFilter(shardContext.newParseContext(parser).parseInnerQueryBuilder()); - if (postFilter != null) { - context.parsedPostFilter(postFilter); - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/query/QueryParseElement.java b/core/src/main/java/org/elasticsearch/search/query/QueryParseElement.java deleted file mode 100644 index cfa4ea21747..00000000000 --- a/core/src/main/java/org/elasticsearch/search/query/QueryParseElement.java +++ /dev/null @@ -1,37 +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.search.query; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.query.QueryShardContext; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class QueryParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - QueryShardContext queryShardContext = context.getQueryShardContext(); - context.parsedQuery(queryShardContext.toQuery(queryShardContext.newParseContext(parser).parseInnerQueryBuilder())); - } -} diff --git a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java index a29831f5a04..1ae80337d76 100644 --- a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -47,7 +47,6 @@ import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.MinimumScoreCollector; import org.elasticsearch.common.lucene.search.FilteredCollector; import org.elasticsearch.search.DocValueFormat; -import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.SearchService; import org.elasticsearch.search.aggregations.AggregationPhase; @@ -60,19 +59,14 @@ import org.elasticsearch.search.profile.Profiler; import org.elasticsearch.search.rescore.RescorePhase; import org.elasticsearch.search.rescore.RescoreSearchContext; import org.elasticsearch.search.sort.SortAndFormats; -import org.elasticsearch.search.sort.TrackScoresParseElement; import org.elasticsearch.search.suggest.SuggestPhase; import java.util.AbstractList; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.concurrent.Callable; -import static java.util.Collections.unmodifiableMap; - /** * */ @@ -89,28 +83,6 @@ public class QueryPhase implements SearchPhase { this.rescorePhase = rescorePhase; } - @Override - public Map parseElements() { - Map parseElements = new HashMap<>(); - parseElements.put("from", new FromParseElement()); - parseElements.put("size", new SizeParseElement()); - parseElements.put("indices_boost", new IndicesBoostParseElement()); - parseElements.put("indicesBoost", new IndicesBoostParseElement()); - parseElements.put("query", new QueryParseElement()); - parseElements.put("post_filter", new PostFilterParseElement()); - parseElements.put("postFilter", new PostFilterParseElement()); - parseElements.put("trackScores", new TrackScoresParseElement()); - parseElements.put("track_scores", new TrackScoresParseElement()); - parseElements.put("min_score", new MinScoreParseElement()); - parseElements.put("minScore", new MinScoreParseElement()); - parseElements.put("timeout", new TimeoutParseElement()); - parseElements.put("terminate_after", new TerminateAfterParseElement()); - parseElements.putAll(aggregationPhase.parseElements()); - parseElements.putAll(suggestPhase.parseElements()); - parseElements.putAll(rescorePhase.parseElements()); - return unmodifiableMap(parseElements); - } - @Override public void preProcess(SearchContext context) { context.preProcess(); diff --git a/core/src/main/java/org/elasticsearch/search/query/SizeParseElement.java b/core/src/main/java/org/elasticsearch/search/query/SizeParseElement.java deleted file mode 100644 index 5560ec939c4..00000000000 --- a/core/src/main/java/org/elasticsearch/search/query/SizeParseElement.java +++ /dev/null @@ -1,44 +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.search.query; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.SearchParseException; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class SizeParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token.isValue()) { - int size = parser.intValue(); - if (size < 0) { - throw new SearchParseException(context, "size is set to [" + size + "] and is expected to be higher or equal to 0", - parser.getTokenLocation()); - } - context.size(size); - } - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/query/TerminateAfterParseElement.java b/core/src/main/java/org/elasticsearch/search/query/TerminateAfterParseElement.java deleted file mode 100644 index fc4b64fe9ac..00000000000 --- a/core/src/main/java/org/elasticsearch/search/query/TerminateAfterParseElement.java +++ /dev/null @@ -1,42 +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.search.query; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * Parser element for 'terminate_after' - */ -public class TerminateAfterParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token == XContentParser.Token.VALUE_NUMBER) { - int terminateAfterCount = parser.intValue(); - if (terminateAfterCount <= 0) { - throw new IllegalArgumentException("terminateAfter must be > 0"); - } - context.terminateAfter(parser.intValue()); - } - } -} diff --git a/core/src/main/java/org/elasticsearch/search/query/TimeoutParseElement.java b/core/src/main/java/org/elasticsearch/search/query/TimeoutParseElement.java deleted file mode 100644 index d57f5362a25..00000000000 --- a/core/src/main/java/org/elasticsearch/search/query/TimeoutParseElement.java +++ /dev/null @@ -1,41 +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.search.query; - -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - */ -public class TimeoutParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token == XContentParser.Token.VALUE_NUMBER) { - context.timeoutInMillis(parser.longValue()); - } else { - context.timeoutInMillis(TimeValue.parseTimeValue(parser.text(), null, "timeout").millis()); - } - } -} - diff --git a/core/src/main/java/org/elasticsearch/search/sort/TrackScoresParseElement.java b/core/src/main/java/org/elasticsearch/search/sort/TrackScoresParseElement.java deleted file mode 100644 index a2eaf54e691..00000000000 --- a/core/src/main/java/org/elasticsearch/search/sort/TrackScoresParseElement.java +++ /dev/null @@ -1,37 +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.search.sort; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.SearchParseElement; -import org.elasticsearch.search.internal.SearchContext; - -/** - * - */ -public class TrackScoresParseElement implements SearchParseElement { - - @Override - public void parse(XContentParser parser, SearchContext context) throws Exception { - XContentParser.Token token = parser.currentToken(); - if (token.isValue()) { - context.trackScores(parser.booleanValue()); - } - } -} \ No newline at end of file diff --git a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java index 071f7375383..ea76dbf7d6c 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java @@ -182,7 +182,8 @@ public class FetchSubPhasePluginIT extends ESIntegTestCase { public static class TermVectorsFetchParseElement extends FetchSubPhaseParseElement { @Override - protected void innerParse(XContentParser parser, TermVectorsFetchContext termVectorsFetchContext, SearchContext searchContext) throws Exception { + protected void innerParse(XContentParser parser, TermVectorsFetchContext termVectorsFetchContext, SearchContext searchContext) + throws Exception { XContentParser.Token token = parser.currentToken(); if (token == XContentParser.Token.VALUE_STRING) { String fieldName = parser.text(); diff --git a/core/src/test/java/org/elasticsearch/search/fetch/FieldDataFieldsTests.java b/core/src/test/java/org/elasticsearch/search/fetch/FieldDataFieldsTests.java deleted file mode 100644 index ba7f70c63a7..00000000000 --- a/core/src/test/java/org/elasticsearch/search/fetch/FieldDataFieldsTests.java +++ /dev/null @@ -1,80 +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.search.fetch; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.fetch.fielddata.FieldDataFieldsParseElement; -import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.TestSearchContext; - -import static org.hamcrest.Matchers.containsString; - -public class FieldDataFieldsTests extends ESTestCase { - - public void testValidFieldDataFieldString() throws Exception { - FieldDataFieldsParseElement parseElement = new FieldDataFieldsParseElement(); - - BytesArray data = new BytesArray(new BytesRef("{\"fielddata_fields\": \"foobar\"}")); - XContentParser parser = XContentFactory.xContent(data).createParser(data); - parser.nextToken(); - parser.nextToken(); - parser.nextToken(); - SearchContext context = new TestSearchContext(null); - parseElement.parse(parser, context); - } - - public void testValidFieldDataFieldArray() throws Exception { - FieldDataFieldsParseElement parseElement = new FieldDataFieldsParseElement(); - - BytesArray data = new BytesArray(new BytesRef("{\"fielddata_fields\": [ \"foo\", \"bar\", \"baz\"]}}")); - XContentParser parser = XContentFactory.xContent(data).createParser(data); - parser.nextToken(); - parser.nextToken(); - parser.nextToken(); - SearchContext context = new TestSearchContext(null); - parseElement.parse(parser, context); - } - - public void testInvalidFieldDataField() throws Exception { - FieldDataFieldsParseElement parseElement = new FieldDataFieldsParseElement(); - - BytesArray data; - if (randomBoolean()) { - data = new BytesArray(new BytesRef("{\"fielddata_fields\": {}}}")); - } else { - data = new BytesArray(new BytesRef("{\"fielddata_fields\": 1.0}}")); - } - XContentParser parser = XContentFactory.xContent(data).createParser(data); - parser.nextToken(); - parser.nextToken(); - parser.nextToken(); - SearchContext context = new TestSearchContext(null); - try { - parseElement.parse(parser, context); - fail("Expected IllegalStateException"); - } catch (IllegalStateException e) { - assertThat(e.getMessage(), containsString("Expected either a VALUE_STRING or an START_ARRAY but got ")); - } - } -}