From e6bce6b36ed490b3e82c66e9995ceb5b4ca0769b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 15 Apr 2016 16:48:11 +0200 Subject: [PATCH] Adapt to changes in core ES (elastic/elasticsearch#17417) Original commit: elastic/x-pack-elasticsearch@2df6d5b27e5090b9b2fce65062a8e265a19a8838 --- .../graph/rest/action/RestGraphAction.java | 32 +++++++++---------- .../input/search/SearchInputFactory.java | 10 +++--- .../search/SearchTransformFactory.java | 12 ++++--- .../watcher/support/WatcherUtilsTests.java | 32 ++++++++----------- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/rest/action/RestGraphAction.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/rest/action/RestGraphAction.java index 6dbac8db07e..5b927f67414 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/rest/action/RestGraphAction.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/rest/action/RestGraphAction.java @@ -5,6 +5,15 @@ */ package org.elasticsearch.graph.rest.action; +import static org.elasticsearch.graph.action.GraphExploreAction.INSTANCE; +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; + +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; @@ -17,10 +26,10 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.graph.action.GraphExploreRequest; +import org.elasticsearch.graph.action.GraphExploreRequest.TermBoost; import org.elasticsearch.graph.action.GraphExploreResponse; import org.elasticsearch.graph.action.Hop; import org.elasticsearch.graph.action.VertexRequest; -import org.elasticsearch.graph.action.GraphExploreRequest.TermBoost; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.rest.BaseRestHandler; @@ -30,15 +39,6 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestToXContentListener; -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -import static org.elasticsearch.graph.action.GraphExploreAction.INSTANCE; -import static org.elasticsearch.rest.RestRequest.Method.GET; -import static org.elasticsearch.rest.RestRequest.Method.POST; - /** * @see GraphExploreRequest */ @@ -85,14 +85,12 @@ public class RestGraphAction extends BaseRestHandler { if (!RestActions.hasBodyContent(request)) { throw new ElasticsearchParseException("Body missing for graph request"); } - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); BytesReference qBytes = RestActions.getRestContent(request); Hop currentHop = graphRequest.createNextHop(null); try(XContentParser parser = XContentFactory.xContent(qBytes).createParser(qBytes)) { - - context.parser(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, parseFieldMatcher); XContentParser.Token token = parser.nextToken(); @@ -107,7 +105,7 @@ public class RestGraphAction extends BaseRestHandler { client.execute(INSTANCE, graphRequest, new RestToXContentListener(channel)); } - private void parseHop(XContentParser parser, QueryParseContext context, Hop currentHop, + private void parseHop(XContentParser parser, QueryParseContext context, Hop currentHop, GraphExploreRequest graphRequest) throws IOException { String fieldName = null; XContentParser.Token token; @@ -198,7 +196,7 @@ public class RestGraphAction extends BaseRestHandler { } } else { throw new ElasticsearchParseException( - "Graph vertices definition " + INCLUDE_FIELD.getPreferredName() + + "Graph vertices definition " + INCLUDE_FIELD.getPreferredName() + " clause has invalid property type:"+ token.name()); } @@ -206,7 +204,7 @@ public class RestGraphAction extends BaseRestHandler { } if (includeTerm == null) { throw new ElasticsearchParseException( - "Graph vertices definition " + INCLUDE_FIELD.getPreferredName() + + "Graph vertices definition " + INCLUDE_FIELD.getPreferredName() + " clause has missing object property for term"); } includes.put(includeTerm, new TermBoost(includeTerm, boost)); @@ -215,7 +213,7 @@ public class RestGraphAction extends BaseRestHandler { includes.put(term, new TermBoost(term, 1f)); } else { throw new ElasticsearchParseException( - "Graph vertices definition " + INCLUDE_FIELD.getPreferredName() + + "Graph vertices definition " + INCLUDE_FIELD.getPreferredName() + " clauses must be string terms or Objects with terms and boosts, not" + token.name()); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/search/SearchInputFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/search/SearchInputFactory.java index dc085e9167a..2ced5f9e5f2 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/search/SearchInputFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/input/search/SearchInputFactory.java @@ -5,6 +5,9 @@ */ package org.elasticsearch.watcher.input.search; +import java.io.IOException; + +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; @@ -18,8 +21,6 @@ import org.elasticsearch.watcher.input.InputFactory; import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput; import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy; -import java.io.IOException; - /** * */ @@ -30,11 +31,13 @@ public class SearchInputFactory extends InputFactory queryParser = MatchAllQueryBuilder::fromXContent; registry.register(queryParser, MatchAllQueryBuilder.QUERY_NAME_FIELD); - QueryParseContext context = new QueryParseContext(registry); - context.reset(parser); + QueryParseContext context = new QueryParseContext(registry, parser, ParseFieldMatcher.STRICT); SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null); assertThat(result.indices(), arrayContainingInAnyOrder(expectedRequest.indices())); @@ -229,8 +226,7 @@ public class WatcherUtilsTests extends ESTestCase { IndicesQueriesRegistry registry = new IndicesQueriesRegistry(); QueryParser queryParser = MatchAllQueryBuilder::fromXContent; registry.register(queryParser, MatchAllQueryBuilder.QUERY_NAME_FIELD); - QueryParseContext context = new QueryParseContext(registry); - context.reset(parser); + QueryParseContext context = new QueryParseContext(registry, parser, ParseFieldMatcher.STRICT); SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null); assertThat(result.indices(), arrayContainingInAnyOrder(indices));