Skip to content

Commit fba7104

Browse files
authored
Refactor the REST actions to clarify what endpoints are deprecated. (#36869)
1 parent b6f59ff commit fba7104

File tree

16 files changed

+53
-25
lines changed

16 files changed

+53
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static Request count(CountRequest countRequest) throws IOException {
479479
}
480480

481481
static Request explain(ExplainRequest explainRequest) throws IOException {
482-
String endpoint = explainRequest.isTypeless()
482+
String endpoint = explainRequest.type().equals(MapperService.SINGLE_MAPPING_NAME)
483483
? endpoint(explainRequest.index(), "_explain", explainRequest.id())
484484
: endpoint(explainRequest.index(), explainRequest.type(), explainRequest.id(), "_explain");
485485
Request request = new Request(HttpGet.METHOD_NAME, endpoint);

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public RestMultiSearchTemplateAction(Settings settings, RestController controlle
6565
controller.registerHandler(POST, "/_msearch/template", this);
6666
controller.registerHandler(GET, "/{index}/_msearch/template", this);
6767
controller.registerHandler(POST, "/{index}/_msearch/template", this);
68+
69+
// Deprecated typed endpoints.
6870
controller.registerHandler(GET, "/{index}/{type}/_msearch/template", this);
6971
controller.registerHandler(POST, "/{index}/{type}/_msearch/template", this);
7072
}

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public RestSearchTemplateAction(Settings settings, RestController controller) {
5454
controller.registerHandler(POST, "/_search/template", this);
5555
controller.registerHandler(GET, "/{index}/_search/template", this);
5656
controller.registerHandler(POST, "/{index}/_search/template", this);
57+
58+
// Deprecated typed endpoints.
5759
controller.registerHandler(GET, "/{index}/{type}/_search/template", this);
5860
controller.registerHandler(POST, "/{index}/{type}/_search/template", this);
5961
}

server/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ public ExplainRequest type(String type) {
9191
return this;
9292
}
9393

94-
public boolean isTypeless() {
95-
return type == null || type.equals(MapperService.SINGLE_MAPPING_NAME);
96-
}
97-
9894
public String id() {
9995
return id;
10096
}

server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ public class RestBulkAction extends BaseRestHandler {
5252

5353
public RestBulkAction(Settings settings, RestController controller) {
5454
super(settings);
55-
5655
controller.registerHandler(POST, "/_bulk", this);
5756
controller.registerHandler(PUT, "/_bulk", this);
5857
controller.registerHandler(POST, "/{index}/_bulk", this);
5958
controller.registerHandler(PUT, "/{index}/_bulk", this);
59+
60+
// Deprecated typed endpoints.
6061
controller.registerHandler(POST, "/{index}/{type}/_bulk", this);
6162
controller.registerHandler(PUT, "/{index}/{type}/_bulk", this);
6263

server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.common.logging.DeprecationLogger;
2727
import org.elasticsearch.common.settings.Settings;
2828
import org.elasticsearch.index.VersionType;
29-
import org.elasticsearch.index.mapper.MapperService;
3029
import org.elasticsearch.rest.BaseRestHandler;
3130
import org.elasticsearch.rest.RestController;
3231
import org.elasticsearch.rest.RestRequest;
@@ -45,6 +44,9 @@ public class RestDeleteAction extends BaseRestHandler {
4544

4645
public RestDeleteAction(Settings settings, RestController controller) {
4746
super(settings);
47+
controller.registerHandler(DELETE, "/{index}/_doc/{id}", this);
48+
49+
// Deprecated typed endpoint.
4850
controller.registerHandler(DELETE, "/{index}/{type}/{id}", this);
4951
}
5052

@@ -55,12 +57,14 @@ public String getName() {
5557

5658
@Override
5759
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
58-
String type = request.param("type");
59-
if (!type.equals(MapperService.SINGLE_MAPPING_NAME)) {
60+
DeleteRequest deleteRequest;
61+
if (request.hasParam("type")) {
6062
deprecationLogger.deprecatedAndMaybeLog("delete_with_types", TYPES_DEPRECATION_MESSAGE);
63+
deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
64+
} else {
65+
deleteRequest = new DeleteRequest(request.param("index"), request.param("id"));
6166
}
6267

63-
DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), type, request.param("id"));
6468
deleteRequest.routing(request.param("routing"));
6569
deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
6670
deleteRequest.setRefreshPolicy(request.param("refresh"));

server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.common.logging.DeprecationLogger;
2828
import org.elasticsearch.common.settings.Settings;
2929
import org.elasticsearch.index.VersionType;
30-
import org.elasticsearch.index.mapper.MapperService;
3130
import org.elasticsearch.rest.BaseRestHandler;
3231
import org.elasticsearch.rest.RestController;
3332
import org.elasticsearch.rest.RestRequest;
@@ -51,6 +50,10 @@ public class RestGetAction extends BaseRestHandler {
5150

5251
public RestGetAction(final Settings settings, final RestController controller) {
5352
super(settings);
53+
controller.registerHandler(GET, "/{index}/_doc/{id}", this);
54+
controller.registerHandler(HEAD, "/{index}/_doc/{id}", this);
55+
56+
// Deprecated typed endpoints.
5457
controller.registerHandler(GET, "/{index}/{type}/{id}", this);
5558
controller.registerHandler(HEAD, "/{index}/{type}/{id}", this);
5659
}
@@ -62,12 +65,14 @@ public String getName() {
6265

6366
@Override
6467
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
65-
String type = request.param("type");
66-
if (!type.equals(MapperService.SINGLE_MAPPING_NAME)) {
68+
GetRequest getRequest;
69+
if (request.hasParam("type")) {
6770
deprecationLogger.deprecatedAndMaybeLog("get_with_types", TYPES_DEPRECATION_MESSAGE);
71+
getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
72+
} else {
73+
getRequest = new GetRequest(request.param("index"), request.param("id"));
6874
}
6975

70-
final GetRequest getRequest = new GetRequest(request.param("index"), type, request.param("id"));
7176
getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
7277
getRequest.routing(request.param("routing"));
7378
getRequest.preference(request.param("preference"));

server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ public class RestIndexAction extends BaseRestHandler {
4848

4949
public RestIndexAction(Settings settings, RestController controller) {
5050
super(settings);
51-
controller.registerHandler(POST, "/{index}/{type}", this); // auto id creation
52-
controller.registerHandler(PUT, "/{index}/{type}/{id}", this);
53-
controller.registerHandler(POST, "/{index}/{type}/{id}", this);
51+
controller.registerHandler(POST, "/{index}/_doc", this); // auto id creation
52+
controller.registerHandler(PUT, "/{index}/_doc/{id}", this);
53+
controller.registerHandler(POST, "/{index}/_doc/{id}", this);
5454

5555
CreateHandler createHandler = new CreateHandler(settings);
5656
controller.registerHandler(PUT, "/{index}/_create/{id}", createHandler);
5757
controller.registerHandler(POST, "/{index}/_create/{id}/", createHandler);
58+
59+
// Deprecated typed endpoints.
60+
controller.registerHandler(POST, "/{index}/{type}", this); // auto id creation
61+
controller.registerHandler(PUT, "/{index}/{type}/{id}", this);
62+
controller.registerHandler(POST, "/{index}/{type}/{id}", this);
5863
controller.registerHandler(PUT, "/{index}/{type}/{id}/_create", createHandler);
5964
controller.registerHandler(POST, "/{index}/{type}/{id}/_create", createHandler);
6065
}

server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public RestMultiGetAction(Settings settings, RestController controller) {
5151
controller.registerHandler(POST, "/_mget", this);
5252
controller.registerHandler(GET, "/{index}/_mget", this);
5353
controller.registerHandler(POST, "/{index}/_mget", this);
54+
55+
// Deprecated typed endpoints.
5456
controller.registerHandler(GET, "/{index}/{type}/_mget", this);
5557
controller.registerHandler(POST, "/{index}/{type}/_mget", this);
5658

server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public RestMultiTermVectorsAction(Settings settings, RestController controller)
4949
controller.registerHandler(POST, "/_mtermvectors", this);
5050
controller.registerHandler(GET, "/{index}/_mtermvectors", this);
5151
controller.registerHandler(POST, "/{index}/_mtermvectors", this);
52+
53+
// Deprecated typed endpoints.
5254
controller.registerHandler(GET, "/{index}/{type}/_mtermvectors", this);
5355
controller.registerHandler(POST, "/{index}/{type}/_mtermvectors", this);
5456
}

0 commit comments

Comments
 (0)