From fba710469a3c28819f2b2678eff99826d48ae769 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Thu, 20 Dec 2018 18:06:41 -0800 Subject: [PATCH] Refactor the REST actions to clarify what endpoints are deprecated. (#36869) --- .../org/elasticsearch/client/RequestConverters.java | 2 +- .../mustache/RestMultiSearchTemplateAction.java | 2 ++ .../script/mustache/RestSearchTemplateAction.java | 2 ++ .../action/explain/ExplainRequest.java | 4 ---- .../rest/action/document/RestBulkAction.java | 3 ++- .../rest/action/document/RestDeleteAction.java | 12 ++++++++---- .../rest/action/document/RestGetAction.java | 13 +++++++++---- .../rest/action/document/RestIndexAction.java | 11 ++++++++--- .../rest/action/document/RestMultiGetAction.java | 2 ++ .../action/document/RestMultiTermVectorsAction.java | 2 ++ .../rest/action/document/RestTermVectorsAction.java | 12 ++++++------ .../rest/action/document/RestUpdateAction.java | 2 ++ .../rest/action/search/RestCountAction.java | 2 ++ .../rest/action/search/RestExplainAction.java | 6 ++++-- .../rest/action/search/RestMultiSearchAction.java | 3 ++- .../rest/action/search/RestSearchAction.java | 2 ++ 16 files changed, 54 insertions(+), 26 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index e89003f007e..63620bd9877 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -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); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java index 3215b9a7306..30543ea236a 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java @@ -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); } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index 7cb346ba8a5..196147bb730 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -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); } diff --git a/server/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java b/server/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java index de8f7c7ccc1..260c63d340a 100644 --- a/server/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java +++ b/server/src/main/java/org/elasticsearch/action/explain/ExplainRequest.java @@ -91,10 +91,6 @@ public class ExplainRequest extends SingleShardRequest implement return this; } - public boolean isTypeless() { - return type == null || type.equals(MapperService.SINGLE_MAPPING_NAME); - } - public String id() { return id; } diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java index 74c30a9f5d0..5cfbbfdb1b5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java @@ -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); diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java index b19bc371794..5100b3d960b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java @@ -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")); diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java index ff0a8c9ccbe..6bef519078a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java @@ -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")); diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 7c10b327cac..adaa4a46fa2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -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); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java index 3684f9b3b08..e466eaf4ee9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java @@ -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); diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java index e76852896a3..bdb00526982 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java @@ -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); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java index 72a2ec3a88f..85ddd3b58ed 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java @@ -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 diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java index b3040a3572f..033176c4a73 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java @@ -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); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java index 3405a344463..04d13133f08 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java @@ -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); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java index dee34921731..2bcc8a5a794 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java @@ -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 diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index 680d55907ee..30791835d30 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -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); diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index cb1efdcd587..8e6e247123d 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -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); }