Refactor the REST actions to clarify what endpoints are deprecated. (#36869)
This commit is contained in:
parent
b6f59ffd71
commit
fba710469a
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue