static <T> ByteBuf serialize(ByteBufAllocator alloc, IndexEntry<T> entry,
    boolean shouldAddType) {
    // Fuzzily assume a general small span is 600 bytes to reduce resizing while building up the
    // JSON. Any extra bytes will be released back after serializing the document.
    ByteBuf document = alloc.heapBuffer(600);
    ByteBuf metadata = alloc.heapBuffer(200);
    try {
      String id = entry.writer().writeDocument(entry.input(), new ByteBufOutputStream(document));
      writeIndexMetadata(new ByteBufOutputStream(metadata), entry, id, shouldAddType);

      ByteBuf payload = alloc.ioBuffer(document.readableBytes() + metadata.readableBytes() + 2);
      try {
        payload.writeBytes(metadata).writeByte('\n').writeBytes(document).writeByte('\n');
      } catch (Throwable t) {
        payload.release();
        propagateIfFatal(t);
        Exceptions.throwUnsafely(t);
      }
      return payload;
    } finally {
      document.release();
      metadata.release();
    }
  }
Creates a bulk request when there is more than one object to store
zipkin-storage/elasticsearch/src/main/java/zipkin2/elasticsearch/internal/BulkCallBuilder.java