/**
  * Saves an entity into elastic search.
  *
  * @param object The entity to save.
  */
 public void save(T object) {
   try {
     IndexRequestBuilder indexRequestBuilder =
         object.getId() == null
             ? client.prepareIndex(index, entity)
             : client.prepareIndex(index, entity, object.getId());
     IndexResponse response =
         indexRequestBuilder.setSource(mapper.writeValueAsString(object)).execute().actionGet();
     // Force refresh.
     object.setId(response.getId());
     client.admin().indices().prepareRefresh(index).execute().actionGet();
     if (logger.isDebugEnabled()) {
       BytesStreamOutput out = new BytesStreamOutput(1024 * 1024);
       response.writeTo(out);
       logger.debug("Obtained response: {}", new String(out.bytes().array()));
     }
   } catch (ElasticSearchException | IOException e) {
     logger.error("Error while saving entity", e);
   }
 }