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:
|
including:
|
||||||
|
|
||||||
[horizontal]
|
[horizontal]
|
||||||
`routing`:: Sets the routing that will be used to route the
|
`routing`:: Routing is used to route the update request to the right shard
|
||||||
document to the relevant 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.
|
`timeout`:: Timeout waiting for a shard to become available.
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
},
|
},
|
||||||
"parent": {
|
"parent": {
|
||||||
"type": "string",
|
"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": {
|
"refresh": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|
|
@ -353,12 +353,12 @@ public class BulkRequest extends ActionRequest<BulkRequest> implements Composite
|
||||||
} else if ("update".equals(action)) {
|
} else if ("update".equals(action)) {
|
||||||
UpdateRequest updateRequest = new UpdateRequest(index, type, id).routing(routing).parent(parent).retryOnConflict(retryOnConflict)
|
UpdateRequest updateRequest = new UpdateRequest(index, type, id).routing(routing).parent(parent).retryOnConflict(retryOnConflict)
|
||||||
.version(version).versionType(versionType)
|
.version(version).versionType(versionType)
|
||||||
|
.routing(routing)
|
||||||
|
.parent(parent)
|
||||||
.source(data.slice(from, nextMarker - from));
|
.source(data.slice(from, nextMarker - from));
|
||||||
|
|
||||||
IndexRequest upsertRequest = updateRequest.upsertRequest();
|
IndexRequest upsertRequest = updateRequest.upsertRequest();
|
||||||
if (upsertRequest != null) {
|
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.timestamp(timestamp);
|
||||||
upsertRequest.ttl(ttl);
|
upsertRequest.ttl(ttl);
|
||||||
upsertRequest.version(version);
|
upsertRequest.version(version);
|
||||||
|
@ -366,8 +366,6 @@ public class BulkRequest extends ActionRequest<BulkRequest> implements Composite
|
||||||
}
|
}
|
||||||
IndexRequest doc = updateRequest.doc();
|
IndexRequest doc = updateRequest.doc();
|
||||||
if (doc != null) {
|
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.timestamp(timestamp);
|
||||||
doc.ttl(ttl);
|
doc.ttl(ttl);
|
||||||
doc.version(version);
|
doc.version(version);
|
||||||
|
|
|
@ -124,9 +124,10 @@ public class UpdateHelper extends AbstractComponent {
|
||||||
indexRequest.index(request.index()).type(request.type()).id(request.id())
|
indexRequest.index(request.index()).type(request.type()).id(request.id())
|
||||||
// it has to be a "create!"
|
// it has to be a "create!"
|
||||||
.create(true)
|
.create(true)
|
||||||
.routing(request.routing())
|
|
||||||
.ttl(ttl)
|
.ttl(ttl)
|
||||||
.refresh(request.refresh())
|
.refresh(request.refresh())
|
||||||
|
.routing(request.routing())
|
||||||
|
.parent(request.parent())
|
||||||
.consistencyLevel(request.consistencyLevel());
|
.consistencyLevel(request.consistencyLevel());
|
||||||
indexRequest.operationThreaded(false);
|
indexRequest.operationThreaded(false);
|
||||||
if (request.versionType() != VersionType.INTERNAL) {
|
if (request.versionType() != VersionType.INTERNAL) {
|
||||||
|
|
|
@ -55,6 +55,9 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||||
@Nullable
|
@Nullable
|
||||||
private String routing;
|
private String routing;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private String parent;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
String script;
|
String script;
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -174,17 +177,6 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||||
return this;
|
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
|
* Controls the shard routing of the request. Using this value to hash the shard
|
||||||
* and not the id.
|
* and not the id.
|
||||||
|
@ -194,6 +186,21 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||||
return this.routing;
|
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() {
|
int shardId() {
|
||||||
return this.shardId;
|
return this.shardId;
|
||||||
}
|
}
|
||||||
|
@ -631,6 +638,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||||
type = in.readString();
|
type = in.readString();
|
||||||
id = in.readString();
|
id = in.readString();
|
||||||
routing = in.readOptionalString();
|
routing = in.readOptionalString();
|
||||||
|
parent = in.readOptionalString();
|
||||||
script = in.readOptionalString();
|
script = in.readOptionalString();
|
||||||
if(Strings.hasLength(script)) {
|
if(Strings.hasLength(script)) {
|
||||||
scriptType = ScriptService.ScriptType.readFrom(in);
|
scriptType = ScriptService.ScriptType.readFrom(in);
|
||||||
|
@ -668,6 +676,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
||||||
out.writeString(type);
|
out.writeString(type);
|
||||||
out.writeString(id);
|
out.writeString(id);
|
||||||
out.writeOptionalString(routing);
|
out.writeOptionalString(routing);
|
||||||
|
out.writeOptionalString(parent);
|
||||||
out.writeOptionalString(script);
|
out.writeOptionalString(script);
|
||||||
if (Strings.hasLength(script)) {
|
if (Strings.hasLength(script)) {
|
||||||
ScriptService.ScriptType.writeTo(scriptType, out);
|
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 updateRequest = new UpdateRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||||
updateRequest.listenerThreaded(false);
|
updateRequest.listenerThreaded(false);
|
||||||
updateRequest.routing(request.param("routing"));
|
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.timeout(request.paramAsTime("timeout", updateRequest.timeout()));
|
||||||
updateRequest.refresh(request.paramAsBoolean("refresh", updateRequest.refresh()));
|
updateRequest.refresh(request.paramAsBoolean("refresh", updateRequest.refresh()));
|
||||||
String consistencyLevel = request.param("consistency");
|
String consistencyLevel = request.param("consistency");
|
||||||
|
|
Loading…
Reference in New Issue