Refactor the REST actions to clarify what endpoints are deprecated. (#36869)

This commit is contained in:
Julie Tibshirani 2018-12-20 18:06:41 -08:00 committed by GitHub
parent b6f59ffd71
commit fba710469a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 54 additions and 26 deletions

View File

@ -479,7 +479,7 @@ final class RequestConverters {
}
static Request explain(ExplainRequest explainRequest) throws IOException {
String endpoint = explainRequest.isTypeless()
String endpoint = explainRequest.type().equals(MapperService.SINGLE_MAPPING_NAME)
? endpoint(explainRequest.index(), "_explain", explainRequest.id())
: endpoint(explainRequest.index(), explainRequest.type(), explainRequest.id(), "_explain");
Request request = new Request(HttpGet.METHOD_NAME, endpoint);

View File

@ -65,6 +65,8 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler {
controller.registerHandler(POST, "/_msearch/template", this);
controller.registerHandler(GET, "/{index}/_msearch/template", this);
controller.registerHandler(POST, "/{index}/_msearch/template", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/_msearch/template", this);
controller.registerHandler(POST, "/{index}/{type}/_msearch/template", this);
}

View File

@ -54,6 +54,8 @@ public class RestSearchTemplateAction extends BaseRestHandler {
controller.registerHandler(POST, "/_search/template", this);
controller.registerHandler(GET, "/{index}/_search/template", this);
controller.registerHandler(POST, "/{index}/_search/template", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/_search/template", this);
controller.registerHandler(POST, "/{index}/{type}/_search/template", this);
}

View File

@ -91,10 +91,6 @@ public class ExplainRequest extends SingleShardRequest<ExplainRequest> implement
return this;
}
public boolean isTypeless() {
return type == null || type.equals(MapperService.SINGLE_MAPPING_NAME);
}
public String id() {
return id;
}

View File

@ -52,11 +52,12 @@ public class RestBulkAction extends BaseRestHandler {
public RestBulkAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_bulk", this);
controller.registerHandler(PUT, "/_bulk", this);
controller.registerHandler(POST, "/{index}/_bulk", this);
controller.registerHandler(PUT, "/{index}/_bulk", this);
// Deprecated typed endpoints.
controller.registerHandler(POST, "/{index}/{type}/_bulk", this);
controller.registerHandler(PUT, "/{index}/{type}/_bulk", this);

View File

@ -26,7 +26,6 @@ import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
@ -45,6 +44,9 @@ public class RestDeleteAction extends BaseRestHandler {
public RestDeleteAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(DELETE, "/{index}/_doc/{id}", this);
// Deprecated typed endpoint.
controller.registerHandler(DELETE, "/{index}/{type}/{id}", this);
}
@ -55,12 +57,14 @@ public class RestDeleteAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String type = request.param("type");
if (!type.equals(MapperService.SINGLE_MAPPING_NAME)) {
DeleteRequest deleteRequest;
if (request.hasParam("type")) {
deprecationLogger.deprecatedAndMaybeLog("delete_with_types", TYPES_DEPRECATION_MESSAGE);
deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
} else {
deleteRequest = new DeleteRequest(request.param("index"), request.param("id"));
}
DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), type, request.param("id"));
deleteRequest.routing(request.param("routing"));
deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
deleteRequest.setRefreshPolicy(request.param("refresh"));

View File

@ -27,7 +27,6 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
@ -51,6 +50,10 @@ public class RestGetAction extends BaseRestHandler {
public RestGetAction(final Settings settings, final RestController controller) {
super(settings);
controller.registerHandler(GET, "/{index}/_doc/{id}", this);
controller.registerHandler(HEAD, "/{index}/_doc/{id}", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/{id}", this);
controller.registerHandler(HEAD, "/{index}/{type}/{id}", this);
}
@ -62,12 +65,14 @@ public class RestGetAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String type = request.param("type");
if (!type.equals(MapperService.SINGLE_MAPPING_NAME)) {
GetRequest getRequest;
if (request.hasParam("type")) {
deprecationLogger.deprecatedAndMaybeLog("get_with_types", TYPES_DEPRECATION_MESSAGE);
getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
} else {
getRequest = new GetRequest(request.param("index"), request.param("id"));
}
final GetRequest getRequest = new GetRequest(request.param("index"), type, request.param("id"));
getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
getRequest.routing(request.param("routing"));
getRequest.preference(request.param("preference"));

View File

@ -48,13 +48,18 @@ public class RestIndexAction extends BaseRestHandler {
public RestIndexAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/{index}/{type}", this); // auto id creation
controller.registerHandler(PUT, "/{index}/{type}/{id}", this);
controller.registerHandler(POST, "/{index}/{type}/{id}", this);
controller.registerHandler(POST, "/{index}/_doc", this); // auto id creation
controller.registerHandler(PUT, "/{index}/_doc/{id}", this);
controller.registerHandler(POST, "/{index}/_doc/{id}", this);
CreateHandler createHandler = new CreateHandler(settings);
controller.registerHandler(PUT, "/{index}/_create/{id}", createHandler);
controller.registerHandler(POST, "/{index}/_create/{id}/", createHandler);
// Deprecated typed endpoints.
controller.registerHandler(POST, "/{index}/{type}", this); // auto id creation
controller.registerHandler(PUT, "/{index}/{type}/{id}", this);
controller.registerHandler(POST, "/{index}/{type}/{id}", this);
controller.registerHandler(PUT, "/{index}/{type}/{id}/_create", createHandler);
controller.registerHandler(POST, "/{index}/{type}/{id}/_create", createHandler);
}

View File

@ -51,6 +51,8 @@ public class RestMultiGetAction extends BaseRestHandler {
controller.registerHandler(POST, "/_mget", this);
controller.registerHandler(GET, "/{index}/_mget", this);
controller.registerHandler(POST, "/{index}/_mget", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/_mget", this);
controller.registerHandler(POST, "/{index}/{type}/_mget", this);

View File

@ -49,6 +49,8 @@ public class RestMultiTermVectorsAction extends BaseRestHandler {
controller.registerHandler(POST, "/_mtermvectors", this);
controller.registerHandler(GET, "/{index}/_mtermvectors", this);
controller.registerHandler(POST, "/{index}/_mtermvectors", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/_mtermvectors", this);
controller.registerHandler(POST, "/{index}/{type}/_mtermvectors", this);
}

View File

@ -53,16 +53,16 @@ public class RestTermVectorsAction extends BaseRestHandler {
public RestTermVectorsAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/{index}/{type}/_termvectors", this);
controller.registerHandler(POST, "/{index}/{type}/_termvectors", this);
controller.registerHandler(GET, "/{index}/{type}/{id}/_termvectors", this);
controller.registerHandler(POST, "/{index}/{type}/{id}/_termvectors", this);
controller.registerHandler(GET, "/{index}/_termvectors", this);
controller.registerHandler(POST, "/{index}/_termvectors", this);
controller.registerHandler(GET, "/{index}/_termvectors/{id}", this);
controller.registerHandler(POST, "/{index}/_termvectors/{id}", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/_termvectors", this);
controller.registerHandler(POST, "/{index}/{type}/_termvectors", this);
controller.registerHandler(GET, "/{index}/{type}/{id}/_termvectors", this);
controller.registerHandler(POST, "/{index}/{type}/{id}/_termvectors", this);
}
@Override

View File

@ -47,6 +47,8 @@ public class RestUpdateAction extends BaseRestHandler {
public RestUpdateAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/{index}/_update/{id}", this);
// Deprecated typed endpoint.
controller.registerHandler(POST, "/{index}/{type}/{id}/_update", this);
}

View File

@ -57,6 +57,8 @@ public class RestCountAction extends BaseRestHandler {
controller.registerHandler(GET, "/_count", this);
controller.registerHandler(POST, "/{index}/_count", this);
controller.registerHandler(GET, "/{index}/_count", this);
// Deprecated typed endpoints.
controller.registerHandler(POST, "/{index}/{type}/_count", this);
controller.registerHandler(GET, "/{index}/{type}/_count", this);
}

View File

@ -49,10 +49,12 @@ public class RestExplainAction extends BaseRestHandler {
public RestExplainAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/{index}/{type}/{id}/_explain", this);
controller.registerHandler(POST, "/{index}/{type}/{id}/_explain", this);
controller.registerHandler(GET, "/{index}/_explain/{id}", this);
controller.registerHandler(POST, "/{index}/_explain/{id}", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/{id}/_explain", this);
controller.registerHandler(POST, "/{index}/{type}/{id}/_explain", this);
}
@Override

View File

@ -68,11 +68,12 @@ public class RestMultiSearchAction extends BaseRestHandler {
public RestMultiSearchAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/_msearch", this);
controller.registerHandler(POST, "/_msearch", this);
controller.registerHandler(GET, "/{index}/_msearch", this);
controller.registerHandler(POST, "/{index}/_msearch", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/_msearch", this);
controller.registerHandler(POST, "/{index}/{type}/_msearch", this);

View File

@ -78,6 +78,8 @@ public class RestSearchAction extends BaseRestHandler {
controller.registerHandler(POST, "/_search", this);
controller.registerHandler(GET, "/{index}/_search", this);
controller.registerHandler(POST, "/{index}/_search", this);
// Deprecated typed endpoints.
controller.registerHandler(GET, "/{index}/{type}/_search", this);
controller.registerHandler(POST, "/{index}/{type}/_search", this);
}