@SuppressWarnings("unchecked")
 protected <T extends ESEntity> T buildEntityFromGetResponse(
     Class<T> entityClass, MultiGetItemResponse item) {
   GetResponse response = item.getResponse();
   if (!response.isExists())
     throw new DaoException(
         String.format(
             "Entity %s does not exist in %s/%s",
             response.getId(), response.getIndex(), response.getType()));
   if (entityClass == null) throw new IllegalArgumentException("Provided Entity class is null");
   else if (entityClass.equals(ESNode.class))
     return (T) ESNode.Builder.buildFromGetReponse(response);
   else if (entityClass.equals(ESWay.class))
     return (T) ESWay.Builder.buildFromGetReponse(response);
   else throw new IllegalArgumentException(entityClass.getSimpleName() + " is not a known Entity");
 }
 protected void saveAllWays(List<Way> ways) {
   Iterator<MultiGetItemResponse> iterator = getNodeItems(ways);
   BulkRequestBuilder bulkRequest = client.prepareBulk();
   for (Way way : ways) {
     try {
       int size = way.getWayNodes().size();
       ESShape shape = getShape(iterator, size);
       ESWay esWay = ESWay.Builder.buildFromEntity(way, shape);
       bulkRequest.add(
           client
               .prepareIndex(indexName, esWay.getEntityType().getIndiceName(), esWay.getIdString())
               .setSource(esWay.toJson()));
     } catch (Exception e) {
       LOG.warning(
           String.format(
               "Unable to add Entity %s to bulk request, cause: %s", way.getId(), e.getMessage()));
     }
   }
   executeBulkRequest(bulkRequest);
 }