Package org.elasticsearch.action.bulk

Examples of org.elasticsearch.action.bulk.BulkResponse


    private static ESLogger logger = Loggers.getLogger(Bulk.class);

    public static void execute(BulkRequestBuilder bulk) {
        logger.info("Executing bulk {} actions", bulk.numberOfActions());
        if (bulk.numberOfActions() > 0) {
            BulkResponse response = bulk.execute().actionGet();
            logger.info("Bulk actions tooks {} ms", response.getTookInMillis());
            if (response.hasFailures()) {
                logger.warn("failed to execute bulk: {}", response.buildFailureMessage());
            }
        } else {
            logger.info("Sorry nothing to do");
        }
    }
View Full Code Here


      String newName = oldName + "_" + Utils.timestamp();

      logger.info("rebuildIndex(): {}", appid);

      BulkRequestBuilder brb = getClient().prepareBulk();
      BulkResponse resp = null;
      Pager pager = new Pager();

      List<ParaObject> list = dao.readPage(appid, null);

      if (!list.isEmpty()) {
        do {
          for (ParaObject obj : list) {
            brb.add(getClient().prepareIndex(appid, obj.getType(), obj.getId()).
                setSource(Utils.getAnnotatedFields(obj)));
            pager.setLastKey(obj.getId());
          }
          // bulk index 1000 objects
          if (brb.numberOfActions() > 100) {
            resp = brb.execute().actionGet();
            logger.info("rebuildIndex(): indexed {}, hasFailures: {}",
                brb.numberOfActions(), resp.hasFailures());
          }
        } while(!(list = dao.readPage(appid, pager)).isEmpty());
      }

      // anything left after loop? index that too
      if (brb.numberOfActions() > 0) {
        resp = brb.execute().actionGet();
        logger.info("rebuildIndex(): indexed {}, hasFailures: {}",
            brb.numberOfActions(), resp.hasFailures());
      }

      // switch to alias NEW_INDEX -> ALIAS, OLD_INDEX -> X
      getClient().admin().indices().prepareAliases().
          addAlias(newName, appid).
View Full Code Here

  public void delete(Long id) {
    this.bulkRequest.add(this.esClient.prepareDelete("photon", "place", String.valueOf(id)));
  }

  private void updateDocuments() {
    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
    if(bulkResponse.hasFailures()) {
      log.error("error while bulk update: " + bulkResponse.buildFailureMessage());
    }
    this.bulkRequest = this.esClient.prepareBulk();
  }
View Full Code Here

  }

  private void saveDocuments() {
    if(this.documentCount < 1) return;

    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
    if(bulkResponse.hasFailures()) {
      log.error("error while bulk import:" + bulkResponse.buildFailureMessage());
    }
    this.bulkRequest = this.esClient.prepareBulk();
  }
View Full Code Here

            }
        }).when(indexInfo).create(any(Message.class));

        Client client = mock(Client.class);
        ActionFuture<BulkResponse> responseActionFuture = mock(ActionFuture.class);
        BulkResponse response = getBulkItemResponses();
        doReturn(response).when(responseActionFuture).actionGet();
        doReturn(responseActionFuture).when(client).bulk(any(BulkRequest.class));

        ActionFuture<IndexResponse> indexResponseActionFuture = mock(ActionFuture.class);
        doReturn(mock(IndexResponse.class)).when(indexResponseActionFuture).actionGet();
View Full Code Here

                        "insert",
                        failure
                        ));
            }
        }
        return new BulkResponse(
                    responseList.toArray(new BulkItemResponse[responseList.size()]),
                    1000
            );
    }
View Full Code Here

    return client.prepareBulk();
  }

  @Override
  public void executeESBulkRequest(BulkRequestBuilder esBulk) throws Exception {
    BulkResponse response = esBulk.execute().actionGet();
    if (response.hasFailures()) {
      throw new ElasticSearchException("Failed to execute ES index bulk update: " + response.buildFailureMessage());
    }
  }
View Full Code Here

                indexRequest.routing(routing);
            }
            bulkRequest.add(indexRequest);
        }
        bulkRequest.refresh(true);
        BulkResponse response = client().bulk(bulkRequest).actionGet();
        if (response.hasFailures()) {
            fail("Error in creating products: " + response.buildFailureMessage());
        }

        assertDocumentCountAfterIndexing(index, products.size() + currentCount);
    }
View Full Code Here

                errors--;
            }

            if(bulkRequest.numberOfActions() > 0) {
                BulkResponse bulkResponse = bulkRequest.execute().actionGet();
                if(bulkResponse.hasFailures()) {
                    log.error("Bulk Request Failed due to: " + bulkResponse.buildFailureMessage());
                }
            }
        }
        catch (RuntimeException re)
        {
View Full Code Here

                        indexRequest.type(typeName).source(builder);
                        bulkRequest.add(indexRequest);
                        count++;
                       
                        if((count % bulkSize) == 0){
                            BulkResponse bulkResponse = bulkRequest.execute().actionGet(bulkTimeout);
                            logger.info("{} objects indexed with ", count, bulkResponse.hasFailures()? "errors" : "success");
                        }                       
                    }
                   
                    if(bulkRequest.numberOfActions() > 0){
                        BulkResponse bulkResponse = bulkRequest.setRefresh(true).execute().actionGet(bulkTimeout);
                        logger.info("{} objects indexed with ", count, bulkResponse.hasFailures()? "errors" : "success");
                    }

                } catch (Exception e) {
                    logger.error("Exception when accessing to LDAP server", e);
                } finally {
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.bulk.BulkResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.