@Override
  public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeByte(comparatorType.id());
    out.writeVInt(requiredSize);
    out.writeVLong(missing);
    out.writeVLong(total);

    out.writeVInt(entries.size());
    for (LongEntry entry : entries) {
      out.writeLong(entry.term);
      out.writeVInt(entry.getCount());
    }
  }
 @Override
 public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
   builder.startObject(getName());
   builder.field(Fields._TYPE, TermsFacet.TYPE);
   builder.field(Fields.MISSING, missing);
   builder.field(Fields.TOTAL, total);
   builder.field(Fields.OTHER, getOtherCount());
   builder.startArray(Fields.TERMS);
   for (LongEntry entry : entries) {
     builder.startObject();
     builder.field(Fields.TERM, entry.term);
     builder.field(Fields.COUNT, entry.getCount());
     builder.endObject();
   }
   builder.endArray();
   builder.endObject();
   return builder;
 }