Skip to content

Commit 075e342

Browse files
authored
Deprecate types in _graph/explore calls. (#40466) (#40515)
Any call that uses a path that sets a type will trigger a deprecation warning.
1 parent 19d2f16 commit 075e342

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/graph/GraphExploreRequest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,26 @@ public GraphExploreRequest indicesOptions(IndicesOptions indicesOptions) {
108108
return this;
109109
}
110110

111+
/**
112+
* The document types to execute the explore against. Defaults to be executed against
113+
* all types.
114+
*
115+
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
116+
* filter on a field on the document.
117+
*/
118+
@Deprecated
111119
public String[] types() {
112120
return this.types;
113121
}
114122

123+
/**
124+
* The document types to execute the explore request against. Defaults to be executed against
125+
* all types.
126+
*
127+
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
128+
* filter on a field on the document.
129+
*/
130+
@Deprecated
115131
public GraphExploreRequest types(String... types) {
116132
this.types = types;
117133
return this;

x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/graph/GraphExploreRequest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,26 @@ public GraphExploreRequest indicesOptions(IndicesOptions indicesOptions) {
9696
return this;
9797
}
9898

99+
/**
100+
* The document types to execute the explore against. Defaults to be executed against
101+
* all types.
102+
*
103+
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
104+
* filter on a field on the document.
105+
*/
106+
@Deprecated
99107
public String[] types() {
100108
return this.types;
101109
}
102110

111+
/**
112+
* The document types to execute the explore request against. Defaults to be executed against
113+
* all types.
114+
*
115+
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
116+
* filter on a field on the document.
117+
*/
118+
@Deprecated
103119
public GraphExploreRequest types(String... types) {
104120
this.types = types;
105121
return this;

x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
public class RestGraphAction extends XPackRestHandler {
4242

4343
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGraphAction.class));
44+
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" +
45+
" Specifying types in graph requests is deprecated.";
4446

4547
public static final ParseField TIMEOUT_FIELD = new ParseField("timeout");
4648
public static final ParseField SIGNIFICANCE_FIELD = new ParseField("use_significance");
@@ -111,7 +113,10 @@ public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPa
111113
parseHop(parser, currentHop, graphRequest);
112114
}
113115

114-
graphRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
116+
if (request.hasParam("type")) {
117+
deprecationLogger.deprecatedAndMaybeLog("graph_with_types", TYPES_DEPRECATION_MESSAGE);
118+
graphRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
119+
}
115120
return channel -> client.es().execute(INSTANCE, graphRequest, new RestToXContentListener<>(channel));
116121
}
117122

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.graph.rest.action;
8+
9+
import org.elasticsearch.common.bytes.BytesArray;
10+
import org.elasticsearch.common.settings.Settings;
11+
import org.elasticsearch.common.xcontent.XContentType;
12+
import org.elasticsearch.rest.RestRequest;
13+
import org.elasticsearch.test.rest.FakeRestRequest;
14+
import org.elasticsearch.test.rest.RestActionTestCase;
15+
import org.junit.Before;
16+
17+
public class RestGraphActionTests extends RestActionTestCase {
18+
19+
@Before
20+
public void setUpAction() {
21+
new RestGraphAction(Settings.EMPTY, controller());
22+
}
23+
24+
public void testTypeInPath() {
25+
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
26+
.withMethod(RestRequest.Method.GET)
27+
.withPath("/some_index/some_type/_graph/explore")
28+
.withContent(new BytesArray("{}"), XContentType.JSON)
29+
.build();
30+
31+
dispatchRequest(request);
32+
assertWarnings(RestGraphAction.TYPES_DEPRECATION_MESSAGE);
33+
}
34+
35+
}

0 commit comments

Comments
 (0)