Package org.elasticsearch.action.bulk

Examples of org.elasticsearch.action.bulk.BulkResponse


    return shapeBuilder.build();
  }

  protected void executeBulkRequest(BulkRequestBuilder bulkRequest) {
    if (bulkRequest.numberOfActions() == 0) return;
    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
    if (!bulkResponse.hasFailures()) return;
    for (BulkItemResponse response : bulkResponse) {
      if (!response.isFailed()) continue;
      LOG.warning(String.format("Unable to save Entity %s in %s/%s, cause: %s",
          response.getId(), response.getIndex(), response.getType(), response.getFailureMessage()));
    }
View Full Code Here


    private Runnable createRunnable(final BulkRequest request) {
        return new Runnable() {
            @Override
            public void run() {
                BulkResponse response = client.bulk(request).actionGet();
                for (BulkItemResponse r : response.getItems()) {
                    String routingKey = ((Message) request.payloads().get(r.getItemId())).getRoutingKey();
                    if (r.isFailed() && !r.getFailureMessage().contains("DocumentAlreadyExistsException")) {
                        log.error("Failed with: " + r.getFailureMessage());
                        Servo.getCounter(
                                MonitorConfig.builder(REJECTED_ROW)
                                        .withTag(SINK_ID, getSinkId())
                                        .withTag(TagKey.ROUTING_KEY, routingKey)
                                        .build()).increment();

                        recover(r.getItemId(), request);
                    } else {
                        Servo.getCounter(
                                MonitorConfig.builder(INDEXED_ROW)
                                        .withTag(SINK_ID, getSinkId())
                                        .withTag(TagKey.ROUTING_KEY, routingKey)
                                        .build()).increment();

                    }
                }

                throughput.increment(response.getItems().length);
            }
        };
    }
View Full Code Here

                    bulk.add(req);
                    nb++;
                    req = queue.poll();
                }
                if (bulk.numberOfActions() > 0) {
                    BulkResponse rep = getNode().client().bulk(bulk).actionGet();
                    for (BulkItemResponse bir : rep.getItems()) {
                        if (bir.isFailed()) {
                            LOGGER.warn("Error executing request: {}", bir.getFailureMessage());
                        }
                    }
                }
View Full Code Here

                    BulkItemResponse response = mock(BulkItemResponse.class);
                    doReturn(false).when(response).isFailed();
                    responses[i] = response;
                }
                ActionFuture<BulkResponse> actionFuture = mock(ActionFuture.class);
                doReturn(new BulkResponse(responses,1000)).when(actionFuture).actionGet();

                return actionFuture;
            }
        }).when(client).bulk(any(BulkRequest.class));
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

    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

                    .setIndex("hackaton")
                    .setType("tweets")
                    .setSource(builder);
            requestBuilder.add(request);
        }
        BulkResponse bulkResponse = requestBuilder.execute().actionGet();
        int items = bulkResponse.getItems().length;
        System.err.print("indexed [" + items + "] items, with failures? [" + bulkResponse.hasFailures()  + "]");
    }
View Full Code Here

                    }

                }
            }

            BulkResponse response = null;
            if (nodes != null && !nodes.isEmpty())
            {
                // bulkRequest.setRefresh(true);
                response = bulkRequest.execute().actionGet();
            }
            return response != null ? response.getItems().length : 0;
        }
        finally
        {
            clear();
        }
View Full Code Here

        new ElasticSearchTestHelper(client).deleteIndexIfItExists("test");
        BulkRequest bulkRequest = new BulkRequestBuilder(client).request();
        URL bulkIndexRequest = this.getClass().getResource("es-numericbulkindex.json");
        byte[] data = ByteStreams.toByteArray(bulkIndexRequest.openStream());
        bulkRequest.add(data, 0, data.length, true);
        BulkResponse bulkResponse = client.bulk(bulkRequest).actionGet();
        if (bulkResponse.hasFailures()) {
            throw new RuntimeException("Failed to index data needed for test. " + bulkResponse.buildFailureMessage());
        }
    }
View Full Code Here

        new ElasticSearchTestHelper(client).deleteIndexIfItExists("test");
        BulkRequest bulkRequest = new BulkRequestBuilder(client).request();
        URL bulkIndexRequest = this.getClass().getResource("es-bulkindex.json");
        byte[] data = ByteStreams.toByteArray(bulkIndexRequest.openStream());
        bulkRequest.add(data, 0, data.length, true);
        BulkResponse bulkResponse = client.bulk(bulkRequest).actionGet();
        if (bulkResponse.hasFailures()) {
            throw new RuntimeException("Failed to index data needed for test. " + bulkResponse.buildFailureMessage());
        }
    }
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.