Esempio n. 1
0
 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));
   }
 }
Esempio n. 2
0
 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()));
   }
 }
Esempio n. 3
0
 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);
 }