Make sure that the parent option on the update request only is delgated to upsert index request.
Closes #4538
This commit is contained in:
parent
75713f4190
commit
6d1a1b328b
|
@ -197,10 +197,15 @@ The update operation supports similar parameters as the index API,
|
|||
including:
|
||||
|
||||
[horizontal]
|
||||
`routing`:: Sets the routing that will be used to route the
|
||||
document to the relevant shard.
|
||||
`routing`:: Routing is used to route the update request to the right shard
|
||||
and sets the routing for the upsert request if the document being
|
||||
updated doesn't exist. Can't be used to update the routing of an
|
||||
existing document.
|
||||
|
||||
`parent`:: Simply sets the routing.
|
||||
`parent`:: Parent is used to route the update request to the right shard
|
||||
and sets the parent for the upsert request if the document being
|
||||
updated doesn't exist. Can't be used to update the `parent` of an
|
||||
existing document.
|
||||
|
||||
`timeout`:: Timeout waiting for a shard to become available.
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
},
|
||||
"parent": {
|
||||
"type": "string",
|
||||
"description": "ID of the parent document"
|
||||
"description": "ID of the parent document. Is is only used for routing and when for the upsert request"
|
||||
},
|
||||
"refresh": {
|
||||
"type": "boolean",
|
||||
|
|
|
@ -353,12 +353,12 @@ public class BulkRequest extends ActionRequest<BulkRequest> implements Composite
|
|||
} else if ("update".equals(action)) {
|
||||
UpdateRequest updateRequest = new UpdateRequest(index, type, id).routing(routing).parent(parent).retryOnConflict(retryOnConflict)
|
||||
.version(version).versionType(versionType)
|
||||
.routing(routing)
|
||||
.parent(parent)
|
||||
.source(data.slice(from, nextMarker - from));
|
||||
|
||||
IndexRequest upsertRequest = updateRequest.upsertRequest();
|
||||
if (upsertRequest != null) {
|
||||
upsertRequest.routing(routing);
|
||||
upsertRequest.parent(parent); // order is important, set it after routing, so it will set the routing
|
||||
upsertRequest.timestamp(timestamp);
|
||||
upsertRequest.ttl(ttl);
|
||||
upsertRequest.version(version);
|
||||
|
@ -366,8 +366,6 @@ public class BulkRequest extends ActionRequest<BulkRequest> implements Composite
|
|||
}
|
||||
IndexRequest doc = updateRequest.doc();
|
||||
if (doc != null) {
|
||||
doc.routing(routing);
|
||||
doc.parent(parent); // order is important, set it after routing, so it will set the routing
|
||||
doc.timestamp(timestamp);
|
||||
doc.ttl(ttl);
|
||||
doc.version(version);
|
||||
|
|
|
@ -118,15 +118,16 @@ public class UpdateHelper extends AbstractComponent {
|
|||
update.setGetResult(getResult);
|
||||
return new Result(update, Operation.NONE, upsertDoc, XContentType.JSON);
|
||||
}
|
||||
indexRequest.source((Map)ctx.get("_source"));
|
||||
indexRequest.source((Map) ctx.get("_source"));
|
||||
}
|
||||
|
||||
indexRequest.index(request.index()).type(request.type()).id(request.id())
|
||||
// it has to be a "create!"
|
||||
.create(true)
|
||||
.routing(request.routing())
|
||||
.ttl(ttl)
|
||||
.refresh(request.refresh())
|
||||
.routing(request.routing())
|
||||
.parent(request.parent())
|
||||
.consistencyLevel(request.consistencyLevel());
|
||||
indexRequest.operationThreaded(false);
|
||||
if (request.versionType() != VersionType.INTERNAL) {
|
||||
|
|
|
@ -55,6 +55,9 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
@Nullable
|
||||
private String routing;
|
||||
|
||||
@Nullable
|
||||
private String parent;
|
||||
|
||||
@Nullable
|
||||
String script;
|
||||
@Nullable
|
||||
|
@ -174,17 +177,6 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent id of this document. Will simply set the routing to this value, as it is only
|
||||
* used for routing with delete requests.
|
||||
*/
|
||||
public UpdateRequest parent(String parent) {
|
||||
if (routing == null) {
|
||||
routing = parent;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls the shard routing of the request. Using this value to hash the shard
|
||||
* and not the id.
|
||||
|
@ -194,6 +186,21 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
return this.routing;
|
||||
}
|
||||
|
||||
/**
|
||||
* The parent id is used for the upsert request and also implicitely sets the routing if not already set.
|
||||
*/
|
||||
public UpdateRequest parent(String parent) {
|
||||
this.parent = parent;
|
||||
if (routing == null) {
|
||||
routing = parent;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String parent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
int shardId() {
|
||||
return this.shardId;
|
||||
}
|
||||
|
@ -631,6 +638,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
type = in.readString();
|
||||
id = in.readString();
|
||||
routing = in.readOptionalString();
|
||||
parent = in.readOptionalString();
|
||||
script = in.readOptionalString();
|
||||
if(Strings.hasLength(script)) {
|
||||
scriptType = ScriptService.ScriptType.readFrom(in);
|
||||
|
@ -668,6 +676,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
out.writeString(type);
|
||||
out.writeString(id);
|
||||
out.writeOptionalString(routing);
|
||||
out.writeOptionalString(parent);
|
||||
out.writeOptionalString(script);
|
||||
if (Strings.hasLength(script)) {
|
||||
ScriptService.ScriptType.writeTo(scriptType, out);
|
||||
|
|
|
@ -57,7 +57,7 @@ public class RestUpdateAction extends BaseRestHandler {
|
|||
UpdateRequest updateRequest = new UpdateRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
updateRequest.listenerThreaded(false);
|
||||
updateRequest.routing(request.param("routing"));
|
||||
updateRequest.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing
|
||||
updateRequest.parent(request.param("parent"));
|
||||
updateRequest.timeout(request.paramAsTime("timeout", updateRequest.timeout()));
|
||||
updateRequest.refresh(request.paramAsBoolean("refresh", updateRequest.refresh()));
|
||||
String consistencyLevel = request.param("consistency");
|
||||
|
|
Loading…
Reference in New Issue