protected void _serializeModel(final XContentBuilder contentBuilder, final ModelT model)
     throws IoExceptionT {
   final ElasticSearchOutputProtocol oprot = new ElasticSearchOutputProtocol(contentBuilder);
   try {
     model.writeAsStruct(oprot);
   } catch (final OutputProtocolException e) {
     throw exceptionFactory.newIoException(
         e, String.format("error serializing model %s", model.getClass().getCanonicalName()));
   }
 }
 public final ModelIdT postModel(
     final Logger logger,
     final Marker logMarker,
     final ModelT model,
     final StringModelIdFactory<ModelIdT> modelIdFactory)
     throws IoExceptionT {
   logger.debug(
       logMarker, "posting %s model to index {}", model.getClass().getCanonicalName(), indexName);
   try {
     return modelIdFactory.createModelId(__prepareIndex(model).execute().actionGet().getId());
   } catch (final ElasticsearchException e) {
     throw exceptionFactory.newIoException(
         e,
         String.format(
             "error posting %s model to index %s",
             model.getClass().getCanonicalName(), indexName));
   }
 }
 private IndexRequestBuilder __prepareIndex(final ModelT model) throws IoExceptionT {
   XContentBuilder modelContentBuilder;
   try {
     modelContentBuilder = XContentFactory.smileBuilder();
   } catch (final IOException e) {
     throw exceptionFactory.newIoException(
         e, String.format("error serializing model %s", model.getClass().getCanonicalName()));
   }
   _serializeModel(modelContentBuilder, model);
   return client.prepareIndex(indexName, documentType).setSource(modelContentBuilder);
 }
 @Path("/{id}")
 @PUT
 public Response update(
     @Auth AuthModelT authModel,
     @PathParam("id") PrimaryKeyT id,
     ModelT model,
     @Context HttpServletRequest request)
     throws HttpCodeException {
   if (!id.equals(model.getId())) {
     throw new HttpInternalServerErrorException("Invalid Request: ID's do not match");
   }
   ModelT updatedModel = man.update(getAuthContext(authModel), model);
   if (updatedModel == null) {
     throw new HttpInternalServerErrorException(
         "Could not update the " + modelClass.getSimpleName());
   }
   return res().success(res().modelData(updatedModel));
 }