serializing get result should use the same construct as search hit fields
This commit is contained in:
parent
58ecc4f77f
commit
c40eaaae38
|
@ -22,6 +22,7 @@ package org.elasticsearch.action.get;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -77,28 +78,7 @@ public class GetField implements Streamable, Iterable<Object> {
|
|||
int size = in.readVInt();
|
||||
values = new ArrayList<Object>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
Object value;
|
||||
byte type = in.readByte();
|
||||
if (type == 0) {
|
||||
value = in.readUTF();
|
||||
} else if (type == 1) {
|
||||
value = in.readInt();
|
||||
} else if (type == 2) {
|
||||
value = in.readLong();
|
||||
} else if (type == 3) {
|
||||
value = in.readFloat();
|
||||
} else if (type == 4) {
|
||||
value = in.readDouble();
|
||||
} else if (type == 5) {
|
||||
value = in.readBoolean();
|
||||
} else if (type == 6) {
|
||||
int bytesSize = in.readVInt();
|
||||
value = new byte[bytesSize];
|
||||
in.readFully(((byte[]) value));
|
||||
} else {
|
||||
throw new IOException("Can't read unknown type [" + type + "]");
|
||||
}
|
||||
values.add(value);
|
||||
values.add(Lucene.readFieldValue(in));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,32 +86,7 @@ public class GetField implements Streamable, Iterable<Object> {
|
|||
out.writeUTF(name);
|
||||
out.writeVInt(values.size());
|
||||
for (Object obj : values) {
|
||||
Class type = obj.getClass();
|
||||
if (type == String.class) {
|
||||
out.writeByte((byte) 0);
|
||||
out.writeUTF((String) obj);
|
||||
} else if (type == Integer.class) {
|
||||
out.writeByte((byte) 1);
|
||||
out.writeInt((Integer) obj);
|
||||
} else if (type == Long.class) {
|
||||
out.writeByte((byte) 2);
|
||||
out.writeLong((Long) obj);
|
||||
} else if (type == Float.class) {
|
||||
out.writeByte((byte) 3);
|
||||
out.writeFloat((Float) obj);
|
||||
} else if (type == Double.class) {
|
||||
out.writeByte((byte) 4);
|
||||
out.writeDouble((Double) obj);
|
||||
} else if (type == Boolean.class) {
|
||||
out.writeByte((byte) 5);
|
||||
out.writeBoolean((Boolean) obj);
|
||||
} else if (type == byte[].class) {
|
||||
out.writeByte((byte) 6);
|
||||
out.writeVInt(((byte[]) obj).length);
|
||||
out.writeBytes(((byte[]) obj));
|
||||
} else {
|
||||
throw new IOException("Can't write type [" + type + "]");
|
||||
}
|
||||
Lucene.writeFieldValue(out, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue