|
@@ -29,11 +29,8 @@ import org.elasticsearch.rest.RestStatus;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
-/**
|
|
|
- */
|
|
|
public class UpdateResponse extends DocWriteResponse {
|
|
|
|
|
|
- private boolean created;
|
|
|
private GetResult getResult;
|
|
|
|
|
|
public UpdateResponse() {
|
|
@@ -43,14 +40,28 @@ public class UpdateResponse extends DocWriteResponse {
|
|
|
* Constructor to be used when a update didn't translate in a write.
|
|
|
* For example: update script with operation set to none
|
|
|
*/
|
|
|
- public UpdateResponse(ShardId shardId, String type, String id, long version, boolean created) {
|
|
|
- this(new ShardInfo(0, 0), shardId, type, id, version, created);
|
|
|
+ public UpdateResponse(ShardId shardId, String type, String id, long version, Operation operation) {
|
|
|
+ this(new ShardInfo(0, 0), shardId, type, id, version, operation);
|
|
|
}
|
|
|
|
|
|
- public UpdateResponse(ShardInfo shardInfo, ShardId shardId, String type, String id, long version, boolean created) {
|
|
|
- super(shardId, type, id, version);
|
|
|
+ public UpdateResponse(ShardInfo shardInfo, ShardId shardId, String type, String id,
|
|
|
+ long version, Operation operation) {
|
|
|
+ super(shardId, type, id, version, operation);
|
|
|
setShardInfo(shardInfo);
|
|
|
- this.created = created;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Operation convert(UpdateHelper.Operation op) {
|
|
|
+ switch(op) {
|
|
|
+ case UPSERT:
|
|
|
+ return Operation.CREATE;
|
|
|
+ case INDEX:
|
|
|
+ return Operation.INDEX;
|
|
|
+ case DELETE:
|
|
|
+ return Operation.DELETE;
|
|
|
+ case NONE:
|
|
|
+ return Operation.NOOP;
|
|
|
+ }
|
|
|
+ throw new IllegalArgumentException();
|
|
|
}
|
|
|
|
|
|
public void setGetResult(GetResult getResult) {
|
|
@@ -65,22 +76,17 @@ public class UpdateResponse extends DocWriteResponse {
|
|
|
* Returns true if document was created due to an UPSERT operation
|
|
|
*/
|
|
|
public boolean isCreated() {
|
|
|
- return this.created;
|
|
|
-
|
|
|
+ return this.operation == Operation.CREATE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RestStatus status() {
|
|
|
- if (created) {
|
|
|
- return RestStatus.CREATED;
|
|
|
- }
|
|
|
- return super.status();
|
|
|
+ return isCreated() ? RestStatus.CREATED : super.status();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void readFrom(StreamInput in) throws IOException {
|
|
|
super.readFrom(in);
|
|
|
- created = in.readBoolean();
|
|
|
if (in.readBoolean()) {
|
|
|
getResult = GetResult.readGetResult(in);
|
|
|
}
|
|
@@ -89,7 +95,6 @@ public class UpdateResponse extends DocWriteResponse {
|
|
|
@Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
super.writeTo(out);
|
|
|
- out.writeBoolean(created);
|
|
|
if (getResult == null) {
|
|
|
out.writeBoolean(false);
|
|
|
} else {
|
|
@@ -122,7 +127,7 @@ public class UpdateResponse extends DocWriteResponse {
|
|
|
builder.append(",type=").append(getType());
|
|
|
builder.append(",id=").append(getId());
|
|
|
builder.append(",version=").append(getVersion());
|
|
|
- builder.append(",created=").append(created);
|
|
|
+ builder.append(",operation=").append(getOperation().getLowercase());
|
|
|
builder.append(",shards=").append(getShardInfo());
|
|
|
return builder.append("]").toString();
|
|
|
}
|