Skip to content

Commit 7fa74c2

Browse files
committed
Delete API: Allow to set _parent on it (will simply set the routing value), closes elastic#742.
1 parent d0bd895 commit 7fa74c2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public BulkRequest add(byte[] data, int from, int length, boolean contentUnsafe)
141141
}
142142

143143
if ("delete".equals(action)) {
144-
add(new DeleteRequest(index, type, id).routing(routing));
144+
add(new DeleteRequest(index, type, id).parent(parent).routing(routing));
145145
} else {
146146
nextMarker = findNextMarker(marker, from, data, length);
147147
if (nextMarker == -1) {

modules/elasticsearch/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ public DeleteRequest timeout(TimeValue timeout) {
167167
return this;
168168
}
169169

170+
/**
171+
* Sets the parent id of this document. Will simply set the routing to this value, as it is only
172+
* used for routing with delete requests.
173+
*/
174+
public DeleteRequest parent(String parent) {
175+
if (routing == null) {
176+
routing = parent;
177+
}
178+
return this;
179+
}
180+
170181
/**
171182
* Controls the shard routing of the request. Using this value to hash the shard
172183
* and not the id.

modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class RestDeleteAction extends BaseRestHandler {
5050

5151
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
5252
DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
53+
deleteRequest.parent(request.param("parent"));
5354
deleteRequest.routing(request.param("routing"));
5455
deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
5556
deleteRequest.refresh(request.paramAsBoolean("refresh", deleteRequest.refresh()));

0 commit comments

Comments
 (0)