From f290d1fe79458c04f378ad14b6945112a75647ec Mon Sep 17 00:00:00 2001 From: Suraj Singh Date: Tue, 7 Jun 2022 08:04:07 -0700 Subject: [PATCH] Revert removal of typed end-points for bulk, search, index APIs (#3524) Reverts the removal of the docType endpoints for bulk, search, and index REST API. This enables bulk API bwc with external clients such as Beats and Logstash until a formal REST Version API mechanism is available for OpenSearch core. Signed-off-by: Suraj Singh (cherry picked from commit f48043b2961280c0da7b8bd5f628898e64181053) --- .../rest/action/document/RestBulkAction.java | 13 ++++++++++- .../action/document/RestDeleteAction.java | 11 ++++++++- .../rest/action/document/RestIndexAction.java | 23 ++++++++++++++++--- .../rest/action/search/RestCountAction.java | 8 ++++++- .../rest/action/search/RestSearchAction.java | 9 +++++++- 5 files changed, 57 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/org/opensearch/rest/action/document/RestBulkAction.java b/server/src/main/java/org/opensearch/rest/action/document/RestBulkAction.java index 3fc02db0a8365..354df5cb22d57 100644 --- a/server/src/main/java/org/opensearch/rest/action/document/RestBulkAction.java +++ b/server/src/main/java/org/opensearch/rest/action/document/RestBulkAction.java @@ -74,7 +74,15 @@ public RestBulkAction(Settings settings) { @Override public List routes() { return unmodifiableList( - asList(new Route(POST, "/_bulk"), new Route(PUT, "/_bulk"), new Route(POST, "/{index}/_bulk"), new Route(PUT, "/{index}/_bulk")) + asList( + new Route(POST, "/_bulk"), + new Route(PUT, "/_bulk"), + new Route(POST, "/{index}/_bulk"), + new Route(PUT, "/{index}/_bulk"), + // Deprecated typed endpoints. + new Route(POST, "/{index}/{type}/_bulk"), + new Route(PUT, "/{index}/{type}/_bulk") + ) ); } @@ -87,6 +95,9 @@ public String getName() { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { BulkRequest bulkRequest = Requests.bulkRequest(); String defaultIndex = request.param("index"); + if (request.hasParam("type")) { + request.param("type"); + } String defaultRouting = request.param("routing"); FetchSourceContext defaultFetchSourceContext = FetchSourceContext.parseFromRestRequest(request); String defaultPipeline = request.param("pipeline"); diff --git a/server/src/main/java/org/opensearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/opensearch/rest/action/document/RestDeleteAction.java index 6b882369a883a..f9961a559b8fc 100644 --- a/server/src/main/java/org/opensearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/opensearch/rest/action/document/RestDeleteAction.java @@ -57,7 +57,13 @@ public class RestDeleteAction extends BaseRestHandler { @Override public List routes() { - return unmodifiableList(asList(new Route(DELETE, "/{index}/_doc/{id}"))); + return unmodifiableList( + asList( + new Route(DELETE, "/{index}/_doc/{id}"), + // Deprecated typed endpoint. + new Route(DELETE, "/{index}/{type}/{id}") + ) + ); } @Override @@ -67,6 +73,9 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + if (request.hasParam("type")) { + request.param("type"); + } DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("id")); deleteRequest.routing(request.param("routing")); deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT)); diff --git a/server/src/main/java/org/opensearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/opensearch/rest/action/document/RestIndexAction.java index e7b1da91aba8f..6556475b7f827 100644 --- a/server/src/main/java/org/opensearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/opensearch/rest/action/document/RestIndexAction.java @@ -63,7 +63,14 @@ public class RestIndexAction extends BaseRestHandler { @Override public List routes() { - return unmodifiableList(asList(new Route(POST, "/{index}/_doc/{id}"), new Route(PUT, "/{index}/_doc/{id}"))); + return unmodifiableList( + asList( + new Route(POST, "/{index}/_doc/{id}"), + new Route(PUT, "/{index}/_doc/{id}"), + new Route(POST, "/{index}/{type}/{id}"), + new Route(PUT, "/{index}/{type}/{id}") + ) + ); } @Override @@ -85,7 +92,14 @@ public String getName() { @Override public List routes() { - return unmodifiableList(asList(new Route(POST, "/{index}/_create/{id}"), new Route(PUT, "/{index}/_create/{id}"))); + return unmodifiableList( + asList( + new Route(POST, "/{index}/_create/{id}"), + new Route(PUT, "/{index}/_create/{id}"), + new Route(POST, "/{index}/{type}/{id}/_create"), + new Route(PUT, "/{index}/{type}/{id}/_create") + ) + ); } @Override @@ -122,7 +136,7 @@ public String getName() { @Override public List routes() { - return unmodifiableList(asList(new Route(POST, "/{index}/_doc"))); + return unmodifiableList(asList(new Route(POST, "/{index}/_doc"), new Route(POST, "/{index}/{type}"))); } @Override @@ -139,6 +153,9 @@ public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { IndexRequest indexRequest = new IndexRequest(request.param("index")); + if (request.hasParam("type")) { + request.param("type"); + } indexRequest.id(request.param("id")); indexRequest.routing(request.param("routing")); indexRequest.setPipeline(request.param("pipeline")); diff --git a/server/src/main/java/org/opensearch/rest/action/search/RestCountAction.java b/server/src/main/java/org/opensearch/rest/action/search/RestCountAction.java index a4a8b2c3b5e56..b8253e959931a 100644 --- a/server/src/main/java/org/opensearch/rest/action/search/RestCountAction.java +++ b/server/src/main/java/org/opensearch/rest/action/search/RestCountAction.java @@ -71,7 +71,10 @@ public List routes() { new Route(GET, "/_count"), new Route(POST, "/_count"), new Route(GET, "/{index}/_count"), - new Route(POST, "/{index}/_count") + new Route(POST, "/{index}/_count"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_count"), + new Route(POST, "/{index}/{type}/_count") ) ); } @@ -83,6 +86,9 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + if (request.hasParam("type")) { + request.param("type"); + } SearchRequest countRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index"))); countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions())); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0).trackTotalHits(true); diff --git a/server/src/main/java/org/opensearch/rest/action/search/RestSearchAction.java b/server/src/main/java/org/opensearch/rest/action/search/RestSearchAction.java index 2db131723bc57..95d1279911c96 100644 --- a/server/src/main/java/org/opensearch/rest/action/search/RestSearchAction.java +++ b/server/src/main/java/org/opensearch/rest/action/search/RestSearchAction.java @@ -105,7 +105,10 @@ public List routes() { new Route(GET, "/_search"), new Route(POST, "/_search"), new Route(GET, "/{index}/_search"), - new Route(POST, "/{index}/_search") + new Route(POST, "/{index}/_search"), + // Deprecated typed endpoints. + new Route(GET, "/{index}/{type}/_search"), + new Route(POST, "/{index}/{type}/_search") ) ); } @@ -197,6 +200,10 @@ public static void parseSearchRequest( searchRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll"))); } + if (request.hasParam("type")) { + request.param("type"); + } + searchRequest.routing(request.param("routing")); searchRequest.preference(request.param("preference")); searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));