Skip to content
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

[Remove] Type mapping parameter from document delete API #2213

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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 @@ -624,8 +624,7 @@ void assertRealtimeGetWorks(final String typeName) throws IOException {
Map<?, ?> hit = (Map<?, ?>) ((List<?>)(XContentMapValues.extractValue("hits.hits", searchResponse))).get(0);
String docId = (String) hit.get("_id");

Request updateRequest = new Request("POST", "/" + index + "/" + typeName + "/" + docId + "/_update");
updateRequest.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE));
Request updateRequest = new Request("POST", "/" + index + "/_update/" + docId);
updateRequest.setJsonEntity("{ \"doc\" : { \"foo\": \"bar\"}}");
client().performRequest(updateRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ public void testUpdateDoc() throws Exception {
for (int i = 0; i < times; i++) {
long value = randomNonNegativeLong();
Request update = new Request("POST", index + "/_update/" + docId);
update.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE));
update.setJsonEntity("{\"doc\": {\"updated_field\": " + value + "}}");
client().performRequest(update);
updates.put(docId, value);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ public class RestDeleteAction extends BaseRestHandler {

@Override
public List<Route> routes() {
return unmodifiableList(
asList(
new Route(DELETE, "/{index}/_doc/{id}"),
// Deprecated typed endpoint.
new Route(DELETE, "/{index}/{type}/{id}")
)
);
return unmodifiableList(asList(new Route(DELETE, "/{index}/_doc/{id}")));
Copy link
Collaborator

@reta reta Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be just "/{index}/{id}"? Afaik, the mapping might be changed from _doc, but the key concept - only single mapping allowed - will stay. May be even better to support both:

asList(
                new Route(DELETE, "/{index}/_doc/{id}"),
                new Route(DELETE, "/{index}/{id}")
            )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking time and reviewing this PR.

Yes, keeping both suggested end-points make sense.
The only point I have it against is document index APIs have either _doc or _create in the path where it provides document index behaviour instead of document type.

But, I think for delete action, we don't need this segregation and we can use both end-points as you suggested.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 makes sense, thanks!

}

@Override
Expand All @@ -73,12 +67,7 @@ public String getName() {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
DeleteRequest deleteRequest;
if (request.hasParam("type")) {
deprecationLogger.deprecate("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 = new DeleteRequest(request.param("index"), request.param("id"));

deleteRequest.routing(request.param("routing"));
deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.action.support.ActiveShardCount;
import org.opensearch.action.update.UpdateRequest;
import org.opensearch.client.node.NodeClient;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.index.VersionType;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.RestRequest;
Expand All @@ -54,19 +53,10 @@
import static org.opensearch.rest.RestRequest.Method.POST;

public class RestUpdateAction extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestUpdateAction.class);
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in "
+ "document update requests is deprecated, use the endpoint /{index}/_update/{id} instead.";

@Override
public List<Route> routes() {
return unmodifiableList(
asList(
new Route(POST, "/{index}/_update/{id}"),
// Deprecated typed endpoint.
new Route(POST, "/{index}/{type}/{id}/_update")
)
);
return unmodifiableList(asList(new Route(POST, "/{index}/_update/{id}")));
}

@Override
Expand All @@ -77,12 +67,7 @@ public String getName() {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
UpdateRequest updateRequest;
if (request.hasParam("type")) {
deprecationLogger.deprecate("update_with_types", TYPES_DEPRECATION_MESSAGE);
updateRequest = new UpdateRequest(request.param("index"), request.param("type"), request.param("id"));
} else {
updateRequest = new UpdateRequest(request.param("index"), request.param("id"));
}
updateRequest = new UpdateRequest(request.param("index"), request.param("id"));

updateRequest.routing(request.param("routing"));
updateRequest.timeout(request.paramAsTime("timeout", updateRequest.timeout()));
Expand Down