Package org.elasticsearch.action.bulk

Examples of org.elasticsearch.action.bulk.BulkResponse


    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


            bulkRequest.add(indexRequestBuilder);
        }

        while (true) {
            try {
                BulkResponse bulkResponse = bulkRequest.execute().actionGet();

                BulkItemResponse[] responses = bulkResponse.getItems();
                List<ElasticsearchObject> failures = new ArrayList<ElasticsearchObject>();
                int numberOfSkippedRecords = 0;
                for (int i = 0; i < responses.length; i++) {
                    if (responses[i].isFailed()) {
                        LOG.error("Record failed with message: " + responses[i].getFailureMessage());
View Full Code Here

            if( bulkBuilder.numberOfActions() > 0 )
            {

                // Execute bulk actions
                BulkResponse bulkResponse = bulkBuilder.execute().actionGet();

                // Handle errors
                if( bulkResponse.hasFailures() )
                {
                    throw new ElasticSearchIndexException( bulkResponse.buildFailureMessage() );
                }

                LOGGER.debug( "Indexing changed Entity states took {}ms", bulkResponse.getTookInMillis() );

                // Refresh index
                support.client().admin().indices().prepareRefresh( support.index() ).execute().actionGet();

            }
View Full Code Here

            final XContentBuilder source = getXContentBuilder(target);
            bulkRequest.add(riverConfig.getClient()
                    .prepareIndex(index, type, id).setSource(source)
                    .setOpType(opType));
        }
        final BulkResponse bulkResponse = bulkRequest.setRefresh(true)
                .execute().actionGet();
        if (bulkResponse.hasFailures()) {
            throw new RobotSystemException(bulkResponse.buildFailureMessage());
        }
    }
View Full Code Here

      if(actionCount != 0 && (actionCount > bulkSize || force == true)){
        try{
          // This is a little slower than passing in an ActionListener
          // to execute(). However, it doesn't spawn thousands of
          // zombie threads that hang out after it's done either.
          BulkResponse response = currentRequest.execute().actionGet();
          if(response.hasFailures()){
            logger.error("failed to execute" + response.buildFailureMessage());
          }
        } catch(Exception e) {
          logger.error("Failed to process bulk", e);
        }
       currentRequest = client.prepareBulk();
View Full Code Here

    private void processBulkIfNeeded(Boolean force) {
      int actionCount = currentRequest.numberOfActions();
      if(actionCount != 0 && (actionCount > bulkSize || force == true)){
        try{
          if(logger.isDebugEnabled()) logger.debug("Executing bulk request: actionCount={} bulkSize={} force={}", actionCount, bulkSize, force);
          BulkResponse response = currentRequest.execute().actionGet();
          if(response.hasFailures()){
            logger.error("failed to execute" + response.buildFailureMessage());
          }
        } catch(Exception e) {
          logger.error("Failed to process bulk", e);
        }
        currentRequest = client.prepareBulk();
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

            } catch (Exception ex) {
                logger.warn("Cannot add object:" + hit + " to bulkIndexing action." + ex.getMessage());
            }
        }
        if (brb.numberOfActions() > 0) {
            BulkResponse rsp = brb.execute().actionGet();
            if (rsp.hasFailures()) {
                List<Integer> list = new ArrayList<Integer>(rsp.getItems().length);
                for (BulkItemResponse br : rsp.getItems()) {
                    if (br.isFailed())
                        list.add(br.getItemId());
                }
                return list;
            }
View Full Code Here

        List<Object> result = null;

        long retriesLeft = this.bulkIndexRetries;
        int attempt = 0;

        BulkResponse response = null;
        do {
            // build the bulk request for this iteration
            BulkRequestBuilder bulkBuilder = client.prepareBulk();
            for (Entry<String,IndexRequest> entry : bulkIndexRequests.entrySet()) {
                bulkBuilder.add(entry.getValue());
            }
            for (Entry<String,DeleteRequest> entry : bulkDeleteRequests.entrySet()) {
                bulkBuilder.add(entry.getValue());
            }

            attempt++;
            result = new ArrayList<Object>();
            if(response != null) {
                // at least second time through
                try {
                    Thread.sleep(this.bulkIndexRetryWaitMs);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            response = bulkBuilder.execute().actionGet();
            if(response != null) {
                for (BulkItemResponse bulkItemResponse : response.getItems()) {
                    if(!bulkItemResponse.isFailed()) {
                        String itemId = bulkItemResponse.getId();
                        String itemRev = revisions.get(itemId);
                        Map<String, Object> itemResponse = new HashMap<String, Object>();
                        itemResponse.put("id", itemId);
                        itemResponse.put("rev", itemRev);
                        result.add(itemResponse);

                        // remove the item from the bulk requests list
                        // so we don't try to index it again
                        bulkIndexRequests.remove(itemId);
                        bulkDeleteRequests.remove(itemId);
                    } else {
                        Failure failure = bulkItemResponse.getFailure();
                        // if the error is fatal don't retry
                        if(failureMessageAppearsFatal(failure.getMessage())) {
                            throw new RuntimeException("indexing error " + failure.getMessage());
                        }
                    }
                }
            }
            retriesLeft--;
        } while((response != null) && (response.hasFailures()) && (retriesLeft > 0));

        if(response == null) {
            throw new RuntimeException("indexing error, bulk response was null");
        }
View Full Code Here

   
// Changes to new ElasticSearch construct (particularly for bulk add)
   
    ElasticSearchManager indexManager = IndexManager.createIndex("test", null, false, null, null, ImmutableSettings.settingsBuilder());
   
    BulkResponse result = null;
    // All docs
    result = indexManager.bulkAddDocuments(IndexManager.mapListToIndex(docset, new TypeToken<Set<DocumentPojo>>(){},
                                  new DocumentPojoIndexMap()), "_id", null, true);
    if (result.hasFailures()) {
      System.out.print("****** FAILED: ");
      System.out.println(result.buildFailureMessage());
    }
   
    //Delete index (once testing complete)
    indexManager.deleteMe();
   
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.