Skip to content

Commit b4bfc42

Browse files
committed
Serialize bucket keys as strings as opposed to optional strings.
1 parent 576e58e commit b4bfc42

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.search.aggregations.bucket.range;
2121

2222
import org.apache.lucene.util.BytesRef;
23+
import org.elasticsearch.Version;
2324
import org.elasticsearch.common.io.stream.StreamInput;
2425
import org.elasticsearch.common.io.stream.StreamOutput;
2526
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -73,17 +74,25 @@ private static String generateKey(BytesRef from, BytesRef to, DocValueFormat for
7374
}
7475

7576
private static Bucket createFromStream(StreamInput in, DocValueFormat format, boolean keyed) throws IOException {
76-
String key = in.readOptionalString();
77+
String key = in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)
78+
? in.readString()
79+
: in.readOptionalString();
80+
7781
BytesRef from = in.readBoolean() ? in.readBytesRef() : null;
7882
BytesRef to = in.readBoolean() ? in.readBytesRef() : null;
7983
long docCount = in.readLong();
8084
InternalAggregations aggregations = InternalAggregations.readAggregations(in);
85+
8186
return new Bucket(format, keyed, key, from, to, docCount, aggregations);
8287
}
8388

8489
@Override
8590
public void writeTo(StreamOutput out) throws IOException {
86-
out.writeOptionalString(key);
91+
if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
92+
out.writeString(key);
93+
} else {
94+
out.writeOptionalString(key);
95+
}
8796
out.writeBoolean(from != null);
8897
if (from != null) {
8998
out.writeBytesRef(from);

0 commit comments

Comments
 (0)