From 1173fcf8ec5046b0963e6e14957a5b9a9730d9d4 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 26 Mar 2019 15:57:41 +0100 Subject: [PATCH 1/5] Deprecate types in `_graph/explore` calls. Any call that uses a path that sets a type will trigger a deprecation warning. --- .../graph/rest/action/RestGraphAction.java | 7 +++- .../graph/action/RestGraphActionTests.java | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/action/RestGraphActionTests.java diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java index 470260a7efac0..f3586c990c195 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java @@ -41,6 +41,8 @@ public class RestGraphAction extends XPackRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGraphAction.class)); + public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + + " Specifying types in graph requests is deprecated."; public static final ParseField TIMEOUT_FIELD = new ParseField("timeout"); public static final ParseField SIGNIFICANCE_FIELD = new ParseField("use_significance"); @@ -111,7 +113,10 @@ public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPa parseHop(parser, currentHop, graphRequest); } - graphRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); + if (request.hasParam("type")) { + deprecationLogger.deprecatedAndMaybeLog("search_with_types", TYPES_DEPRECATION_MESSAGE); + graphRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); + } return channel -> client.es().execute(INSTANCE, graphRequest, new RestToXContentListener<>(channel)); } diff --git a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/action/RestGraphActionTests.java b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/action/RestGraphActionTests.java new file mode 100644 index 0000000000000..5366c68c95fa5 --- /dev/null +++ b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/action/RestGraphActionTests.java @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.graph.action; + +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.test.rest.FakeRestRequest; +import org.elasticsearch.test.rest.RestActionTestCase; +import org.elasticsearch.xpack.graph.rest.action.RestGraphAction; +import org.junit.Before; + +public class RestGraphActionTests extends RestActionTestCase { + + @Before + public void setUpAction() { + new RestGraphAction(Settings.EMPTY, controller()); + } + + public void testTypeInPath() { + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.GET) + .withPath("/some_index/some_type/_graph/explore") + .withContent(new BytesArray("{}"), XContentType.JSON) + .build(); + + dispatchRequest(request); + assertWarnings(RestGraphAction.TYPES_DEPRECATION_MESSAGE); + } + +} From fdf4371bbe8bbdc6fd623edf112011b4beb04404 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 26 Mar 2019 16:00:15 +0100 Subject: [PATCH 2/5] iter --- .../xpack/graph/{ => rest}/action/RestGraphActionTests.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/{ => rest}/action/RestGraphActionTests.java (91%) diff --git a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/action/RestGraphActionTests.java b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java similarity index 91% rename from x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/action/RestGraphActionTests.java rename to x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java index 5366c68c95fa5..486ac4e70e346 100644 --- a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/action/RestGraphActionTests.java +++ b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.graph.action; +package org.elasticsearch.xpack.graph.rest.action; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; @@ -12,7 +12,6 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.RestActionTestCase; -import org.elasticsearch.xpack.graph.rest.action.RestGraphAction; import org.junit.Before; public class RestGraphActionTests extends RestActionTestCase { From c4ed26a49c13ad7d330b4659717f1f24d1f33066 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 26 Mar 2019 16:01:24 +0100 Subject: [PATCH 3/5] rename --- .../elasticsearch/xpack/graph/rest/action/RestGraphAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java index f3586c990c195..130d6deed567f 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java @@ -114,7 +114,7 @@ public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPa } if (request.hasParam("type")) { - deprecationLogger.deprecatedAndMaybeLog("search_with_types", TYPES_DEPRECATION_MESSAGE); + deprecationLogger.deprecatedAndMaybeLog("graph_with_types", TYPES_DEPRECATION_MESSAGE); graphRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); } return channel -> client.es().execute(INSTANCE, graphRequest, new RestToXContentListener<>(channel)); From ae220cbce5bc922ce8c467166414c3d5ad048d36 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 27 Mar 2019 09:31:29 +0100 Subject: [PATCH 4/5] Deprecate types in requests as well. --- .../client/graph/GraphExploreRequest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java index 4d2a000a00c89..4b26b51466681 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java @@ -108,10 +108,25 @@ public GraphExploreRequest indicesOptions(IndicesOptions indicesOptions) { return this; } + /** + * The document types to execute the explore against. Defaults to be executed against + * all types. + * + * @deprecated Types are in the process of being removed. Instead of using a type, prefer to + * filter on a field on the document. + */ public String[] types() { return this.types; } + /** + * The document types to execute the explore request against. Defaults to be executed against + * all types. + * + * @deprecated Types are in the process of being removed. Instead of using a type, prefer to + * filter on a field on the document. + */ + @Deprecated public GraphExploreRequest types(String... types) { this.types = types; return this; From 225244289ed4252752b43f01b8fd4996048a1280 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 27 Mar 2019 09:32:28 +0100 Subject: [PATCH 5/5] iter --- .../client/graph/GraphExploreRequest.java | 1 + .../xpack/graph/GraphExploreRequest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java index 4b26b51466681..3040b8a121cf7 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java @@ -115,6 +115,7 @@ public GraphExploreRequest indicesOptions(IndicesOptions indicesOptions) { * @deprecated Types are in the process of being removed. Instead of using a type, prefer to * filter on a field on the document. */ + @Deprecated public String[] types() { return this.types; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/graph/GraphExploreRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/graph/GraphExploreRequest.java index 196982c0a35fb..c1a682757d140 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/graph/GraphExploreRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/graph/GraphExploreRequest.java @@ -96,10 +96,26 @@ public GraphExploreRequest indicesOptions(IndicesOptions indicesOptions) { return this; } + /** + * The document types to execute the explore against. Defaults to be executed against + * all types. + * + * @deprecated Types are in the process of being removed. Instead of using a type, prefer to + * filter on a field on the document. + */ + @Deprecated public String[] types() { return this.types; } + /** + * The document types to execute the explore request against. Defaults to be executed against + * all types. + * + * @deprecated Types are in the process of being removed. Instead of using a type, prefer to + * filter on a field on the document. + */ + @Deprecated public GraphExploreRequest types(String... types) { this.types = types; return this;