Skip to content

Commit

Permalink
[ILM] change remove-policy-from-index http method from DELETE to POST (
Browse files Browse the repository at this point in the history
…#35268)

The remove-ilm-from-index API was using the DELETE http method
to signify that something is being removed. Although, metadata
about ILM for the index is being deleted, no entity/resource
is being deleted during this operation. POST is more in line with
what this API is actually doing, it is modifying the metadata for
an index. As part of this change, `remove` is also appended to the path 
to be more explicit about its actions.
  • Loading branch information
talevy authored Nov 6, 2018
1 parent a937d7f commit a85b4f4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ static Request deleteLifecyclePolicy(DeleteLifecyclePolicyRequest deleteLifecycl
static Request removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyRequest removePolicyRequest) {
String[] indices = removePolicyRequest.indices() == null ?
Strings.EMPTY_ARRAY : removePolicyRequest.indices().toArray(new String[] {});
Request request = new Request(HttpDelete.METHOD_NAME,
Request request = new Request(HttpPost.METHOD_NAME,
new RequestConverters.EndpointBuilder()
.addCommaSeparatedPathParts(indices)
.addPathPartAsIs("_ilm")
.addPathPartAsIs("_ilm", "remove")
.build());
RequestConverters.Params params = new RequestConverters.Params(request);
params.withIndicesOptions(removePolicyRequest.indicesOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public void testRemoveIndexLifecyclePolicy() {
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);

Request request = IndexLifecycleRequestConverters.removeIndexLifecyclePolicy(req);
assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME));
assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
String idxString = Strings.arrayToCommaDelimitedString(indices);
assertThat(request.getEndpoint(), equalTo("/" + (idxString.isEmpty() ? "" : (idxString + "/")) + "_ilm"));
assertThat(request.getEndpoint(), equalTo("/" + (idxString.isEmpty() ? "" : (idxString + "/")) + "_ilm/remove"));
assertThat(request.getParameters(), equalTo(expectedParams));
}

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/ilm/apis/remove-policy.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Unassigns a policy from a specified index pattern

==== Request

`DELETE <index>/_ilm`
`POST <index>/_ilm/remove`

==== Description

Expand Down Expand Up @@ -80,7 +80,7 @@ PUT my_index

[source,js]
--------------------------------------------------
DELETE my_index/_ilm
POST my_index/_ilm/remove
--------------------------------------------------
// CONSOLE
// TEST[continued]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RestRemoveIndexLifecyclePolicyAction extends BaseRestHandler {

public RestRemoveIndexLifecyclePolicyAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.DELETE, "/{index}/_ilm", this);
controller.registerHandler(RestRequest.Method.POST, "/{index}/_ilm/remove", this);
}

@Override
Expand All @@ -40,4 +40,4 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
return channel ->
client.execute(RemoveIndexLifecyclePolicyAction.INSTANCE, changePolicyRequest, new RestToXContentListener<>(channel));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ilm.remove_policy": {
"documentation": "http://www.elastic.co/guide/en/index_lifecycle/current/index_lifecycle.html",
"methods": [ "DELETE" ],
"methods": [ "POST" ],
"url": {
"path": "/{index}/_ilm",
"paths": ["/{index}/_ilm", "/_ilm"],
"path": "/{index}/_ilm/remove",
"paths": ["/{index}/_ilm/remove", "/_ilm/remove"],
"parts": {
"index": {
"type" : "string",
Expand Down

0 comments on commit a85b4f4

Please sign in to comment.