Skip to content

Commit c42d9d9

Browse files
authored
Deprecate X-Pack centric SQL endpoints (elastic#35964)
This commit is part of our plan to deprecate and ultimately remove the use of _xpack in the REST APIs.
1 parent e50e0f9 commit c42d9d9

File tree

18 files changed

+76
-39
lines changed

18 files changed

+76
-39
lines changed

docs/reference/sql/endpoints/rest.asciidoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and returns the results. For example:
99

1010
[source,js]
1111
--------------------------------------------------
12-
POST /_xpack/sql?format=txt
12+
POST /_sql?format=txt
1313
{
1414
"query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5"
1515
}
@@ -48,7 +48,7 @@ specified then the response is returned in the same format as the request.
4848

4949
[source,js]
5050
--------------------------------------------------
51-
POST /_xpack/sql?format=json
51+
POST /_sql?format=json
5252
{
5353
"query": "SELECT * FROM library ORDER BY page_count DESC",
5454
"fetch_size": 5
@@ -85,7 +85,7 @@ case of text format the cursor is returned as `Cursor` http header.
8585

8686
[source,js]
8787
--------------------------------------------------
88-
POST /_xpack/sql?format=json
88+
POST /_sql?format=json
8989
{
9090
"cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWYUpOYklQMHhRUEtld3RsNnFtYU1hQQ==:BAFmBGRhdGUBZgVsaWtlcwFzB21lc3NhZ2UBZgR1c2Vy9f///w8="
9191
}
@@ -123,7 +123,7 @@ To clear the state earlier, you can use the clear cursor command:
123123

124124
[source,js]
125125
--------------------------------------------------
126-
POST /_xpack/sql/close
126+
POST /_sql/close
127127
{
128128
"cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWYUpOYklQMHhRUEtld3RsNnFtYU1hQQ==:BAFmBGRhdGUBZgVsaWtlcwFzB21lc3NhZ2UBZgR1c2Vy9f///w8="
129129
}
@@ -152,7 +152,7 @@ parameter.
152152

153153
[source,js]
154154
--------------------------------------------------
155-
POST /_xpack/sql?format=txt
155+
POST /_sql?format=txt
156156
{
157157
"query": "SELECT * FROM library ORDER BY page_count DESC",
158158
"filter": {

docs/reference/sql/endpoints/translate.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ into native Elasticsearch queries. For example:
88

99
[source,js]
1010
--------------------------------------------------
11-
POST /_xpack/sql/translate
11+
POST /_sql/translate
1212
{
1313
"query": "SELECT * FROM library ORDER BY page_count DESC",
1414
"fetch_size": 10

docs/reference/sql/getting-started.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ And now you can execute SQL using the <<sql-rest>> right away:
2222

2323
[source,js]
2424
--------------------------------------------------
25-
POST /_xpack/sql?format=txt
25+
POST /_sql?format=txt
2626
{
2727
"query": "SELECT * FROM library WHERE release_date < '2000-01-01'"
2828
}

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/XPackIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void testBasicFeature() throws IOException {
6161
bulk.addParameter("refresh", "true");
6262
client().performRequest(bulk);
6363

64-
Request sql = new Request("POST", "/_xpack/sql");
64+
Request sql = new Request("POST", "/_sql");
6565
sql.setJsonEntity("{\"query\": \"SELECT * FROM sql_test WHERE f > 1 ORDER BY f ASC\"}");
6666
String response = EntityUtils.toString(client().performRequest(sql).getEntity());
6767
assertEquals("{\"columns\":[{\"name\":\"f\",\"type\":\"text\"}],\"rows\":[[\"2\"]]}", response);

x-pack/plugin/sql/qa/multi-node/src/test/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlMultinodeIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private void assertCount(RestClient client, int count) throws IOException {
110110
expected.put("columns", singletonList(columnInfo(mode, "COUNT(1)", "long", JDBCType.BIGINT, 20)));
111111
expected.put("rows", singletonList(singletonList(count)));
112112

113-
Request request = new Request("POST", "/_xpack/sql");
113+
Request request = new Request("POST", "/_sql");
114114
if (false == mode.isEmpty()) {
115115
request.addParameter("mode", mode);
116116
}

x-pack/plugin/sql/qa/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private static Map<String, Object> runSql(@Nullable String asUser, String mode,
177177
}
178178

179179
private static Map<String, Object> runSql(@Nullable String asUser, String mode, HttpEntity entity) throws IOException {
180-
Request request = new Request("POST", "/_xpack/sql");
180+
Request request = new Request("POST", "/_sql");
181181
if (false == mode.isEmpty()) {
182182
request.addParameter("mode", mode);
183183
}

x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private Map<String, Object> runSql(String mode, HttpEntity sql) throws IOExcepti
314314
}
315315

316316
private Map<String, Object> runSql(String mode, HttpEntity sql, String suffix) throws IOException {
317-
Request request = new Request("POST", "/_xpack/sql" + suffix);
317+
Request request = new Request("POST", "/_sql" + suffix);
318318
request.addParameter("error_trace", "true"); // Helps with debugging in case something crazy happens on the server.
319319
request.addParameter("pretty", "true"); // Improves error reporting readability
320320
if (randomBoolean()) {
@@ -646,7 +646,7 @@ private Tuple<String, String> runSqlAsText(String sql, String accept) throws IOE
646646
* rather than the {@code format} parameter.
647647
*/
648648
private Tuple<String, String> runSqlAsText(String suffix, HttpEntity entity, String accept) throws IOException {
649-
Request request = new Request("POST", "/_xpack/sql" + suffix);
649+
Request request = new Request("POST", "/_sql" + suffix);
650650
request.addParameter("error_trace", "true");
651651
request.setEntity(entity);
652652
RequestOptions.Builder options = request.getOptions().toBuilder();
@@ -664,7 +664,7 @@ private Tuple<String, String> runSqlAsText(String suffix, HttpEntity entity, Str
664664
* rather than an {@code Accept} header.
665665
*/
666666
private Tuple<String, String> runSqlAsTextFormat(String sql, String format) throws IOException {
667-
Request request = new Request("POST", "/_xpack/sql");
667+
Request request = new Request("POST", "/_sql");
668668
request.addParameter("error_trace", "true");
669669
request.addParameter("format", format);
670670
request.setJsonEntity("{\"query\":\"" + sql + "\"}");

x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlUsageTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private void index(List<IndexDocument> docs) throws IOException {
223223
}
224224

225225
private Map<String, Object> getStats() throws UnsupportedOperationException, IOException {
226-
Request request = new Request("GET", "/_xpack/sql/stats");
226+
Request request = new Request("GET", "/_sql/stats");
227227
Map<String, Object> responseAsMap;
228228
try (InputStream content = client().performRequest(request).getEntity().getContent()) {
229229
responseAsMap = XContentHelper.convertToMap(JsonXContent.jsonXContent, content, false);
@@ -233,7 +233,7 @@ private Map<String, Object> getStats() throws UnsupportedOperationException, IOE
233233
}
234234

235235
private void runTranslate(String sql) throws IOException {
236-
Request request = new Request("POST", "/_xpack/sql/translate");
236+
Request request = new Request("POST", "/_sql/translate");
237237
if (randomBoolean()) {
238238
// We default to JSON but we force it randomly for extra coverage
239239
request.addParameter("format", "json");
@@ -267,7 +267,7 @@ private void assertTranslateQueryMetric(int expected, Map<String, Object> respon
267267
}
268268

269269
private void runSql(String mode, String restClient, String sql) throws IOException {
270-
Request request = new Request("POST", "/_xpack/sql");
270+
Request request = new Request("POST", "/_sql");
271271
request.addParameter("error_trace", "true"); // Helps with debugging in case something crazy happens on the server.
272272
request.addParameter("pretty", "true"); // Improves error reporting readability
273273
if (randomBoolean()) {

x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/JreHttpUrlConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class JreHttpUrlConnection implements Closeable {
4747
* error.
4848
*/
4949
public static final String SQL_STATE_BAD_SERVER = "bad_server";
50-
private static final String SQL_NOT_AVAILABLE_ERROR_MESSAGE = "request [/_xpack/sql] contains unrecognized parameter: [mode]";
50+
private static final String SQL_NOT_AVAILABLE_ERROR_MESSAGE = "request [/_sql] contains unrecognized parameter: [mode]";
5151

5252
public static <R> R http(String path, String query, ConnectionConfiguration cfg, Function<JreHttpUrlConnection, R> handler) {
5353
final URI uriPath = cfg.baseUri().resolve(path); // update path if needed

x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/Protocol.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ public final class Protocol {
2626
/**
2727
* SQL-related endpoints
2828
*/
29-
public static final String CLEAR_CURSOR_REST_ENDPOINT = "/_xpack/sql/close";
30-
public static final String SQL_QUERY_REST_ENDPOINT = "/_xpack/sql";
31-
public static final String SQL_STATS_REST_ENDPOINT = "/_xpack/sql/stats";
29+
public static final String CLEAR_CURSOR_REST_ENDPOINT = "/_sql/close";
30+
public static final String CLEAR_CURSOR_DEPRECATED_REST_ENDPOINT = "/_xpack/sql/close";
31+
public static final String SQL_QUERY_REST_ENDPOINT = "/_sql";
32+
public static final String SQL_QUERY_DEPRECATED_REST_ENDPOINT = "/_xpack/sql";
33+
public static final String SQL_STATS_REST_ENDPOINT = "/_sql/stats";
34+
public static final String SQL_STATS_DEPRECATED_REST_ENDPOINT = "/_xpack/sql/stats";
3235
}

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
67
package org.elasticsearch.xpack.sql.plugin;
78

9+
import org.apache.logging.log4j.LogManager;
810
import org.elasticsearch.client.node.NodeClient;
11+
import org.elasticsearch.common.logging.DeprecationLogger;
912
import org.elasticsearch.common.settings.Settings;
1013
import org.elasticsearch.common.xcontent.XContentParser;
1114
import org.elasticsearch.rest.BaseRestHandler;
@@ -21,11 +24,16 @@
2124

2225
import static org.elasticsearch.rest.RestRequest.Method.POST;
2326

24-
2527
public class RestSqlClearCursorAction extends BaseRestHandler {
26-
public RestSqlClearCursorAction(Settings settings, RestController controller) {
28+
29+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlClearCursorAction.class));
30+
31+
RestSqlClearCursorAction(Settings settings, RestController controller) {
2732
super(settings);
28-
controller.registerHandler(POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT, this);
33+
// TODO: remove deprecated endpoint in 8.0.0
34+
controller.registerWithDeprecatedHandler(
35+
POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT, this,
36+
POST, Protocol.CLEAR_CURSOR_DEPRECATED_REST_ENDPOINT, deprecationLogger);
2937
}
3038

3139
@Override
@@ -39,6 +47,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
3947

4048
@Override
4149
public String getName() {
42-
return "xpack_sql_clear_cursor_action";
50+
return "sql_clear_cursor";
4351
}
52+
4453
}

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
67
package org.elasticsearch.xpack.sql.plugin;
78

9+
import org.apache.logging.log4j.LogManager;
810
import org.elasticsearch.Version;
911
import org.elasticsearch.client.node.NodeClient;
12+
import org.elasticsearch.common.logging.DeprecationLogger;
1013
import org.elasticsearch.common.settings.Settings;
1114
import org.elasticsearch.common.xcontent.XContentBuilder;
1215
import org.elasticsearch.common.xcontent.XContentParser;
@@ -37,12 +40,21 @@
3740
import static org.elasticsearch.xpack.sql.proto.RequestInfo.CLI;
3841

3942
public class RestSqlQueryAction extends BaseRestHandler {
43+
44+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlQueryAction.class));
45+
4046
private static String CLIENT_ID = "client.id";
4147

42-
public RestSqlQueryAction(Settings settings, RestController controller) {
48+
RestSqlQueryAction(Settings settings, RestController controller) {
4349
super(settings);
44-
controller.registerHandler(GET, Protocol.SQL_QUERY_REST_ENDPOINT, this);
45-
controller.registerHandler(POST, Protocol.SQL_QUERY_REST_ENDPOINT, this);
50+
// TODO: remove deprecated endpoint in 8.0.0
51+
controller.registerWithDeprecatedHandler(
52+
GET, Protocol.SQL_QUERY_REST_ENDPOINT, this,
53+
GET, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, deprecationLogger);
54+
// TODO: remove deprecated endpoint in 8.0.0
55+
controller.registerWithDeprecatedHandler(
56+
POST, Protocol.SQL_QUERY_REST_ENDPOINT, this,
57+
POST, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, deprecationLogger);
4658
}
4759

4860
@Override
@@ -131,6 +143,7 @@ public RestResponse buildResponse(SqlQueryResponse response) throws Exception {
131143

132144
@Override
133145
public String getName() {
134-
return "xpack_sql_query_action";
146+
return "sql_query";
135147
}
148+
136149
}

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
package org.elasticsearch.xpack.sql.plugin;
88

9+
import org.apache.logging.log4j.LogManager;
910
import org.elasticsearch.client.node.NodeClient;
11+
import org.elasticsearch.common.logging.DeprecationLogger;
1012
import org.elasticsearch.common.settings.Settings;
1113
import org.elasticsearch.rest.BaseRestHandler;
1214
import org.elasticsearch.rest.RestController;
@@ -20,14 +22,19 @@
2022

2123
public class RestSqlStatsAction extends BaseRestHandler {
2224

25+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlStatsAction.class));
26+
2327
protected RestSqlStatsAction(Settings settings, RestController controller) {
2428
super(settings);
25-
controller.registerHandler(GET, Protocol.SQL_STATS_REST_ENDPOINT, this);
29+
// TODO: remove deprecated endpoint in 8.0.0
30+
controller.registerWithDeprecatedHandler(
31+
GET, Protocol.SQL_STATS_REST_ENDPOINT, this,
32+
GET, Protocol.SQL_STATS_DEPRECATED_REST_ENDPOINT, deprecationLogger);
2633
}
2734

2835
@Override
2936
public String getName() {
30-
return "xpack_sql_stats_action";
37+
return "sql_stats";
3138
}
3239

3340
@Override

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
public class RestSqlTranslateAction extends BaseRestHandler {
2828
public RestSqlTranslateAction(Settings settings, RestController controller) {
2929
super(settings);
30-
controller.registerHandler(GET, "/_xpack/sql/translate", this);
31-
controller.registerHandler(POST, "/_xpack/sql/translate", this);
30+
controller.registerHandler(GET, "/_sql/translate", this);
31+
controller.registerHandler(POST, "/_sql/translate", this);
3232
}
3333

3434
@Override

x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.sql.clear_cursor.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"documentation": "Clear SQL cursor",
44
"methods": [ "POST"],
55
"url": {
6-
"path": "/_xpack/sql/close",
7-
"paths": [ "/_xpack/sql/close" ],
6+
"path": "/_sql/close",
7+
"paths": [ "/_sql/close" ],
88
"parts": {}
99
},
1010
"body": {

x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.sql.query.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"documentation": "Execute SQL",
44
"methods": [ "POST", "GET" ],
55
"url": {
6-
"path": "/_xpack/sql",
7-
"paths": [ "/_xpack/sql" ],
6+
"path": "/_sql",
7+
"paths": [ "/_sql" ],
88
"parts": {},
99
"params": {
1010
"format": {

x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.sql.translate.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"documentation": "Translate SQL into Elasticsearch queries",
44
"methods": [ "POST", "GET" ],
55
"url": {
6-
"path": "/_xpack/sql/translate",
7-
"paths": [ "/_xpack/sql/translate" ],
6+
"path": "/_sql/translate",
7+
"paths": [ "/_sql/translate" ],
88
"parts": {},
99
"params": {}
1010
},

x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,12 @@ public void testSqlFailsOnIndexWithTwoTypes() throws IOException {
428428
client().performRequest(doc2);
429429
return;
430430
}
431-
Request sqlRequest = new Request("POST", "/_xpack/sql");
431+
final Request sqlRequest;
432+
if (isRunningAgainstOldCluster()) {
433+
sqlRequest = new Request("POST", "/_xpack/sql");
434+
} else {
435+
sqlRequest = new Request("POST", "/_sql");
436+
}
432437
sqlRequest.setJsonEntity("{\"query\":\"SELECT * FROM testsqlfailsonindexwithtwotypes\"}");
433438
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(sqlRequest));
434439
assertEquals(400, e.getResponse().getStatusLine().getStatusCode());

0 commit comments

Comments
 (0)