|
@@ -40,6 +40,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.index.mapper.MapperService;
|
|
|
import org.elasticsearch.index.seqno.SequenceNumbers;
|
|
|
+import org.elasticsearch.index.shard.ShardId;
|
|
|
import org.elasticsearch.rest.RestStatus;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -359,6 +360,26 @@ public class BulkItemResponse implements Writeable, StatusToXContentObject {
|
|
|
|
|
|
BulkItemResponse() {}
|
|
|
|
|
|
+ BulkItemResponse(ShardId shardId, StreamInput in) throws IOException {
|
|
|
+ id = in.readVInt();
|
|
|
+ opType = OpType.fromId(in.readByte());
|
|
|
+
|
|
|
+ byte type = in.readByte();
|
|
|
+ if (type == 0) {
|
|
|
+ response = new IndexResponse(shardId, in);
|
|
|
+ } else if (type == 1) {
|
|
|
+ response = new DeleteResponse(shardId, in);
|
|
|
+ } else if (type == 3) { // make 3 instead of 2, because 2 is already in use for 'no responses'
|
|
|
+ response = new UpdateResponse(shardId, in);
|
|
|
+ } else if (type != 2) {
|
|
|
+ throw new IllegalArgumentException("Unexpected type [" + type + "]");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (in.readBoolean()) {
|
|
|
+ failure = new Failure(in);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
BulkItemResponse(StreamInput in) throws IOException {
|
|
|
id = in.readVInt();
|
|
|
opType = OpType.fromId(in.readByte());
|
|
@@ -370,6 +391,8 @@ public class BulkItemResponse implements Writeable, StatusToXContentObject {
|
|
|
response = new DeleteResponse(in);
|
|
|
} else if (type == 3) { // make 3 instead of 2, because 2 is already in use for 'no responses'
|
|
|
response = new UpdateResponse(in);
|
|
|
+ } else if (type != 2) {
|
|
|
+ throw new IllegalArgumentException("Unexpected type [" + type + "]");
|
|
|
}
|
|
|
|
|
|
if (in.readBoolean()) {
|
|
@@ -473,13 +496,7 @@ public class BulkItemResponse implements Writeable, StatusToXContentObject {
|
|
|
if (response == null) {
|
|
|
out.writeByte((byte) 2);
|
|
|
} else {
|
|
|
- if (response instanceof IndexResponse) {
|
|
|
- out.writeByte((byte) 0);
|
|
|
- } else if (response instanceof DeleteResponse) {
|
|
|
- out.writeByte((byte) 1);
|
|
|
- } else if (response instanceof UpdateResponse) {
|
|
|
- out.writeByte((byte) 3); // make 3 instead of 2, because 2 is already in use for 'no responses'
|
|
|
- }
|
|
|
+ writeResponseType(out);
|
|
|
response.writeTo(out);
|
|
|
}
|
|
|
if (failure == null) {
|
|
@@ -489,4 +506,34 @@ public class BulkItemResponse implements Writeable, StatusToXContentObject {
|
|
|
failure.writeTo(out);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void writeThin(StreamOutput out) throws IOException {
|
|
|
+ out.writeVInt(id);
|
|
|
+ out.writeByte(opType.getId());
|
|
|
+
|
|
|
+ if (response == null) {
|
|
|
+ out.writeByte((byte) 2);
|
|
|
+ } else {
|
|
|
+ writeResponseType(out);
|
|
|
+ response.writeThin(out);
|
|
|
+ }
|
|
|
+ if (failure == null) {
|
|
|
+ out.writeBoolean(false);
|
|
|
+ } else {
|
|
|
+ out.writeBoolean(true);
|
|
|
+ failure.writeTo(out);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void writeResponseType(StreamOutput out) throws IOException {
|
|
|
+ if (response instanceof IndexResponse) {
|
|
|
+ out.writeByte((byte) 0);
|
|
|
+ } else if (response instanceof DeleteResponse) {
|
|
|
+ out.writeByte((byte) 1);
|
|
|
+ } else if (response instanceof UpdateResponse) {
|
|
|
+ out.writeByte((byte) 3); // make 3 instead of 2, because 2 is already in use for 'no responses'
|
|
|
+ } else {
|
|
|
+ throw new IllegalStateException("Unexpected response type found [" + response.getClass() + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|