public byte[] buildAsBytes(XContentType contentType) throws SearchSourceBuilderException {
   try {
     XContentBuilder builder = XContentFactory.contentBinaryBuilder(contentType);
     toXContent(builder, EMPTY_PARAMS);
     return builder.copiedBytes();
   } catch (Exception e) {
     throw new SearchSourceBuilderException("Failed to build search source", e);
   }
 }
 public FastByteArrayOutputStream buildAsUnsafeBytes(XContentType contentType)
     throws SearchSourceBuilderException {
   try {
     BinaryXContentBuilder builder = XContentFactory.contentBinaryBuilder(contentType);
     toXContent(builder, ToXContent.EMPTY_PARAMS);
     return builder.unsafeStream();
   } catch (Exception e) {
     throw new SearchSourceBuilderException("Failed to build search source", e);
   }
 }