Skip to content

Commit

Permalink
Serialize bucket keys as strings as opposed to optional strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani committed May 23, 2018
1 parent 576e58e commit b4bfc42
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.search.aggregations.bucket.range;

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand Down Expand Up @@ -73,17 +74,25 @@ private static String generateKey(BytesRef from, BytesRef to, DocValueFormat for
}

private static Bucket createFromStream(StreamInput in, DocValueFormat format, boolean keyed) throws IOException {
String key = in.readOptionalString();
String key = in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)
? in.readString()
: in.readOptionalString();

BytesRef from = in.readBoolean() ? in.readBytesRef() : null;
BytesRef to = in.readBoolean() ? in.readBytesRef() : null;
long docCount = in.readLong();
InternalAggregations aggregations = InternalAggregations.readAggregations(in);

return new Bucket(format, keyed, key, from, to, docCount, aggregations);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(key);
if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
out.writeString(key);
} else {
out.writeOptionalString(key);
}
out.writeBoolean(from != null);
if (from != null) {
out.writeBytesRef(from);
Expand Down

0 comments on commit b4bfc42

Please sign in to comment.