Package org.elasticsearch.action.bulk

Examples of org.elasticsearch.action.bulk.BulkResponse


        BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
        for (int i = 0; i < 10; i++) {
            bulkRequestBuilder.add(client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
                    .setPercolate("*"));
        }
        BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
        assertThat(bulkResponse.hasFailures(), equalTo(false));
        for (BulkItemResponse bulkItemResponse : bulkResponse) {
            IndexResponse index = bulkItemResponse.response();
            assertThat(index.matches().size(), equalTo(1));
            assertThat(index.matches(), hasItem("kuku"));
        }
View Full Code Here


                            logger.trace("executing bulk with [{}] actions", bulkRequestBuilder.numberOfActions());
                        }

                        if (ordered) {
                            try {
                                BulkResponse response = bulkRequestBuilder.execute().actionGet();
                                if (response.hasFailures()) {
                                    // TODO write to exception queue?
                                    logger.warn("failed to execute" + response.buildFailureMessage());
                                }
                                for (Long deliveryTag : deliveryTags) {
                                    try {
                                        channel.basicAck(deliveryTag, false);
                                    } catch (IOException e1) {
                                        logger.warn("failed to ack [{}]", e1, deliveryTag);
                                    }
                                }
                            } catch (Exception e) {
                                logger.warn("failed to execute bulk", e);
                            }
                        } else {
                            bulkRequestBuilder.execute(new ActionListener<BulkResponse>() {
                                @Override public void onResponse(BulkResponse response) {
                                    if (response.hasFailures()) {
                                        // TODO write to exception queue?
                                        logger.warn("failed to execute" + response.buildFailureMessage());
                                    }
                                    for (Long deliveryTag : deliveryTags) {
                                        try {
                                            channel.basicAck(deliveryTag, false);
                                        } catch (IOException e1) {
View Full Code Here

                        logger.warn("failed to add last_seq entry to bulk indexing");
                    }
                }

                try {
                    BulkResponse response = bulk.execute().actionGet();
                    if (response.hasFailures()) {
                        // TODO write to exception queue?
                        logger.warn("failed to execute" + response.buildFailureMessage());
                    }
                } catch (Exception e) {
                    logger.warn("failed to execute bulk", e);
                }
            }
View Full Code Here

  @Override
  public void commit() throws IOException {
    if (execute != null) {
      // wait for previous to finish
      long beforeWait = System.currentTimeMillis();
      BulkResponse actionGet = execute.actionGet();
      if (actionGet.hasFailures()) {
        for (BulkItemResponse item : actionGet) {
          if (item.isFailed()) {
            throw new RuntimeException("First failure in bulk: "
                    + item.getFailureMessage());
          }
        }
      }
      long msWaited = System.currentTimeMillis() - beforeWait;
      LOG.info("Previous took in ms " + actionGet.getTookInMillis()
              + ", including wait " + msWaited);
      execute = null;
    }
    if (bulk != null) {
      if (bulkDocs > 0) {
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, deleting the old index
      switchIndexToAlias(oldName, newName, appid, true);
    } catch (Exception e) {
View Full Code Here

                })
                .toList();

            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");
            }
        } catch(Throwable e) {
View Full Code Here

  private void processExecute(boolean createNewBulk) {
    if (execute != null) {
      // wait for previous to finish
      long beforeWait = System.currentTimeMillis();
      BulkResponse actionGet = execute.actionGet();
      if (actionGet.hasFailures()) {
        for (BulkItemResponse item : actionGet) {
          if (item.failed()) {
            throw new RuntimeException("First failure in bulk: "
                + item.getFailureMessage());
          }
        }
      }
      long msWaited = System.currentTimeMillis() - beforeWait;
      LOG.info("Previous took in ms " + actionGet.getTookInMillis()
          + ", including wait " + msWaited);
      execute = null;
    }
    if (bulk != null) {
      if (bulkDocs > 0) {
View Full Code Here

          sinkCounter.incrementBatchCompleteCount();
        }

        sinkCounter.addToEventDrainAttemptCount(size);

        BulkResponse bulkResponse = bulkRequest.execute().actionGet();
        if (bulkResponse.hasFailures()) {
          throw new EventDeliveryException(bulkResponse.buildFailureMessage());
        }
      }
      txn.commit();
      sinkCounter.addToEventDrainSuccessCount(size);
      counterGroup.incrementAndGet("transaction.success");
View Full Code Here

            }
            bulkRequest.add(prepareIndex);
        }

        ListenableActionFuture<BulkResponse> future = bulkRequest.execute();
        BulkResponse bulkResponse = future.actionGet();

        List<String> indexedIds = new LinkedList<String>();
        for (BulkItemResponse response : bulkResponse.getItems()) {
            indexedIds.add(response.getId());
        }
        log.debug("List of successfully indexed document ids : {}", indexedIds);
        exchange.getIn().setBody(indexedIds);
    }
View Full Code Here

    private void executeBulkRequest() {
        if (bulk.numberOfActions() == 0) return;
        long secondsSinceLastUpdate = System.currentTimeMillis() / 1000 - startTimestamp;
        if (bulk.numberOfActions() < MAX_BULK_SIZE && secondsSinceLastUpdate < 10) return;

        BulkResponse bulkResponse = null;
        final Timer.Context context = bulkRequestTimer.time();
        try {
            bulkResponse = bulk.execute().actionGet();
        } finally {
            context.stop();
        }
        logStatistics(bulkResponse.getItems().length);
        reset();
    }
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.