コード例 #1
0
 @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");
 }
コード例 #2
0
 protected void saveAllNodes(List<Node> nodes) {
   BulkRequestBuilder bulkRequest = client.prepareBulk();
   for (Node node : nodes) {
     try {
       ESNode esNode = ESNode.Builder.buildFromEntity(node);
       bulkRequest.add(
           client
               .prepareIndex(
                   indexName, esNode.getEntityType().getIndiceName(), esNode.getIdString())
               .setSource(esNode.toJson()));
     } catch (Exception exception) {
       LOG.warning(
           String.format(
               "Unable to add Entity %s to bulk request, cause: %s",
               node.getId(), exception.getMessage()));
     }
   }
   executeBulkRequest(bulkRequest);
 }