Package org.elasticsearch.action.bulk

Examples of org.elasticsearch.action.bulk.BulkResponse


  public void bulkIndex(List<IndexQuery> queries) {
    BulkRequestBuilder bulkRequest = client.prepareBulk();
    for (IndexQuery query : queries) {
      bulkRequest.add(prepareIndex(query));
    }
    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
    if (bulkResponse.hasFailures()) {
      Map<String, String> failedDocuments = new HashMap<String, String>();
      for (BulkItemResponse item : bulkResponse.getItems()) {
        if (item.isFailed())
          failedDocuments.put(item.getId(), item.getFailureMessage());
      }
      throw new ElasticsearchException(
          "Bulk indexing has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages ["
View Full Code Here


    }
  }

  private void executeBulk(BulkRequestBuilder bulkRequest) {
    if (bulkRequest.numberOfActions()>0) {
      BulkResponse bulkResponse = bulkRequest.execute().actionGet();

      if (bulkResponse.hasFailures()) {
        logger.warn("Bulk index failed: "+bulkResponse.buildFailureMessage());
        throw new RuntimeException("Bulk request failed");
      }
    }
  }
View Full Code Here

    long normTime = processActionsIntoQueries(bulkRequestBuilder, actions);

    if (bulkRequestBuilder.numberOfActions() > 0) {
      // execute the request
      long indexTime = System.currentTimeMillis();
      BulkResponse response = bulkRequestBuilder.setRefresh(false).get();

      indexTime = System.currentTimeMillis() - indexTime;

      long refreshTime = 0;
      if (refreshRequired) {
        refreshTime = this.refreshRequiredIndex(indices);
      }

      LOGGER.debug("-- submitted {} items with {}ms in normalization, {}ms indexing and {}ms refresh({}). Total: {}ms",
        bulkRequestBuilder.numberOfActions(), normTime, indexTime, refreshTime, indices, (normTime + indexTime + refreshTime));

      if (response.hasFailures()) {
        throw new IllegalStateException("Errors while indexing stack: " + response.buildFailureMessage());
      }
    }
  }
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

    @Override
    public void after() {
        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

    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

      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

            }
        }

        log.debug("Ready to index {} {} into Elasticsearch.", collection.size(), type);

        BulkResponse response = request.execute().actionGet();
        if (response.hasFailures()) {
            int errorCount = 0;
            for (BulkItemResponse itemResponse : response) {
                if (itemResponse.failed()) {
                    log.error("The " + type + " of id " + itemResponse.getId() + " wasn't indexed in bulk operation: " + itemResponse.getFailureMessage());
                    ++errorCount;
View Full Code Here

    BulkRequestBuilder bulkRequestBuilderMocked = mock(BulkRequestBuilder.class);
    when(bulkRequestBuilderMocked.numberOfActions()).thenReturn(1);

    ListenableActionFuture<BulkResponse> listenableActionFutureMocked = mock(ListenableActionFuture.class);
    when(bulkRequestBuilderMocked.execute()).thenReturn(listenableActionFutureMocked);
    BulkResponse bulkResponseMocked = mock(BulkResponse.class);
    when(listenableActionFutureMocked.actionGet()).thenReturn(bulkResponseMocked);
    when(bulkResponseMocked.hasFailures()).thenReturn(false);

    // Action
    entityDao.executeBulkRequest(bulkRequestBuilderMocked);

    // Assert
View Full Code Here

    BulkRequestBuilder bulkRequestBuilderMocked = mock(BulkRequestBuilder.class);
    when(bulkRequestBuilderMocked.numberOfActions()).thenReturn(1);

    ListenableActionFuture<BulkResponse> listenableActionFutureMocked = mock(ListenableActionFuture.class);
    when(bulkRequestBuilderMocked.execute()).thenReturn(listenableActionFutureMocked);
    BulkResponse bulkResponseMocked = mock(BulkResponse.class);
    when(listenableActionFutureMocked.actionGet()).thenReturn(bulkResponseMocked);
    when(bulkResponseMocked.hasFailures()).thenReturn(true);

    Iterator<BulkItemResponse> iteratorMocked = mock(Iterator.class);
    when(bulkResponseMocked.iterator()).thenReturn(iteratorMocked);
    BulkItemResponse response1 = mock(BulkItemResponse.class);
    when(response1.isFailed()).thenReturn(true);
    when(iteratorMocked.hasNext()).thenReturn(true, false);
    when(iteratorMocked.next()).thenReturn(response1);
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.