Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ static Request count(CountRequest countRequest) throws IOException {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public RestMultiSearchTemplateAction(Settings settings, RestController controlle
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public RestSearchTemplateAction(Settings settings, RestController controller) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ public ExplainRequest type(String type) {
return this;
}

public boolean isTypeless() {
return type == null || type.equals(MapperService.SINGLE_MAPPING_NAME);
}

public String id() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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;
Expand All @@ -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);
}

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

@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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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;
Expand All @@ -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);
}
Expand All @@ -62,12 +65,14 @@ public String getName() {

@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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public RestMultiGetAction(Settings settings, RestController controller) {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public RestMultiTermVectorsAction(Settings settings, RestController controller)
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ public class RestTermVectorsAction extends BaseRestHandler {

public RestTermVectorsAction(Settings settings, RestController controller) {
super(settings);
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);

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);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public RestCountAction(Settings settings, RestController controller) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public RestSearchAction(Settings settings, RestController controller) {
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);
}
Expand Down