ensure bwc wire compatibility

This commit is contained in:
Areek Zillur 2016-10-04 14:24:33 -04:00
parent bd4a03a426
commit 40b4f39f9f
2 changed files with 24 additions and 9 deletions

View File

@ -105,16 +105,16 @@ public interface DocumentRequest<T> extends IndicesRequest {
* Requested operation type to perform on the document
*/
enum OpType {
/**
* Creates the resource. Simply adds it to the index, if there is an existing
* document with the id, then it won't be removed.
*/
CREATE(0),
/**
* Index the source. If there an existing document with the id, it will
* be replaced.
*/
INDEX(1),
INDEX(0),
/**
* Creates the resource. Simply adds it to the index, if there is an existing
* document with the id, then it won't be removed.
*/
CREATE(1),
/** Updates a document */
UPDATE(2),
/** Deletes a document */
@ -138,12 +138,22 @@ public interface DocumentRequest<T> extends IndicesRequest {
public static OpType fromId(byte id) {
switch (id) {
case 0: return CREATE;
case 1: return INDEX;
case 0: return INDEX;
case 1: return CREATE;
case 2: return UPDATE;
case 3: return DELETE;
default: throw new IllegalArgumentException("Unknown opType: [" + id + "]");
}
}
public static OpType fromString(String sOpType) {
String lowerCase = sOpType.toLowerCase(Locale.ENGLISH);
for (OpType opType : OpType.values()) {
if (opType.getLowercase().equals(lowerCase)) {
return opType;
}
}
throw new IllegalArgumentException("Unknown opType: [" + sOpType + "]");
}
}
}

View File

@ -21,6 +21,7 @@ package org.elasticsearch.action.bulk;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.DocumentRequest.OpType;
import org.elasticsearch.action.delete.DeleteResponse;
@ -301,7 +302,11 @@ public class BulkItemResponse implements Streamable, StatusToXContent {
@Override
public void readFrom(StreamInput in) throws IOException {
id = in.readVInt();
if (in.getVersion().onOrAfter(Version.V_6_0_0_alpha1)) {
opType = OpType.fromId(in.readByte());
} else {
opType = OpType.fromString(in.readString());
}
byte type = in.readByte();
if (type == 0) {