Package org.elasticsearch.action.bulk

Examples of org.elasticsearch.action.bulk.BulkResponse


  @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


    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 execute() throws Exception {
    try {
      logger.info("Sending bulk to elasticsearch cluster");
      BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
      if (bulkResponse.hasFailures()) {
        throw new EventDeliveryException(bulkResponse.buildFailureMessage());
      }
    } finally {
      bulkRequestBuilder = client.prepareBulk();
    }
  }
View Full Code Here

                        request.add(Requests.indexRequest("test").type("child").id(Integer.toString(counter) + "_" + k)
                                .parent(Integer.toString(counter))
                                .source(childSource(Integer.toString(counter), "tag" + k)));
                    }
                }
                BulkResponse response = request.execute().actionGet();
                if (response.hasFailures()) {
                    System.err.println("--> failures...");
                }
                if (((i * BATCH) % 10000) == 0) {
                    System.out.println("--> Indexed " + (i * BATCH) * (1 + CHILD_COUNT) + " took " + stopWatch.stop().lastTaskTime());
                    stopWatch.start();
View Full Code Here

            BulkRequestBuilder request = client1.prepareBulk();
            for (int j = 0; j < BATCH; j++) {
                counter++;
                request.add(Requests.indexRequest("test").type("type1").id(Integer.toString(counter)).source(source(Integer.toString(counter), "test" + counter)));
            }
            BulkResponse response = request.execute().actionGet();
            if (response.hasFailures()) {
                System.err.println("failures...");
            }
            if (((i * BATCH) % 10000) == 0) {
                System.out.println("Indexed " + (i * BATCH) + " took " + stopWatch.stop().lastTaskTime());
                stopWatch.start();
View Full Code Here

                            .field("date", new Date())
                            .endObject();
                    request.add(Requests.indexRequest("test").type("type1").id(Integer.toString(counter))
                            .source(source));
                }
                BulkResponse response = request.execute().actionGet();
                if (response.hasFailures()) {
                    System.err.println("--> failures...");
                }
                if (((i * BATCH) % 10000) == 0) {
                    System.out.println("--> Indexed " + (i * BATCH) + " took " + stopWatch.stop().lastTaskTime());
                    stopWatch.start();
View Full Code Here

        ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

        BulkResponse bulkResponse = client1.prepareBulk()
                .add(client1.prepareIndex().setIndex("test").setType("type1").setId("1").setSource(source("1", "test")))
                .add(client1.prepareIndex().setIndex("test").setType("type1").setId("2").setSource(source("2", "test")).setCreate(true))
                .add(client1.prepareIndex().setIndex("test").setType("type1").setSource(source("3", "test")))
                .add(client1.prepareDelete().setIndex("test").setType("type1").setId("1"))
                .add(client1.prepareIndex().setIndex("test").setType("type1").setSource("{ xxx }")) // failure
                .execute().actionGet();

        assertThat(bulkResponse.hasFailures(), equalTo(true));
        assertThat(bulkResponse.items().length, equalTo(5));

        assertThat(bulkResponse.items()[0].isFailed(), equalTo(false));
        assertThat(bulkResponse.items()[0].opType(), equalTo("index"));
        assertThat(bulkResponse.items()[0].index(), equalTo(getConcreteIndexName()));
        assertThat(bulkResponse.items()[0].type(), equalTo("type1"));
        assertThat(bulkResponse.items()[0].id(), equalTo("1"));

        assertThat(bulkResponse.items()[1].isFailed(), equalTo(false));
        assertThat(bulkResponse.items()[1].opType(), equalTo("create"));
        assertThat(bulkResponse.items()[1].index(), equalTo(getConcreteIndexName()));
        assertThat(bulkResponse.items()[1].type(), equalTo("type1"));
        assertThat(bulkResponse.items()[1].id(), equalTo("2"));

        assertThat(bulkResponse.items()[2].isFailed(), equalTo(false));
        assertThat(bulkResponse.items()[2].opType(), equalTo("create"));
        assertThat(bulkResponse.items()[2].index(), equalTo(getConcreteIndexName()));
        assertThat(bulkResponse.items()[2].type(), equalTo("type1"));
        String generatedId3 = bulkResponse.items()[2].id();

        assertThat(bulkResponse.items()[3].isFailed(), equalTo(false));
        assertThat(bulkResponse.items()[3].opType(), equalTo("delete"));
        assertThat(bulkResponse.items()[3].index(), equalTo(getConcreteIndexName()));
        assertThat(bulkResponse.items()[3].type(), equalTo("type1"));
        assertThat(bulkResponse.items()[3].id(), equalTo("1"));

        assertThat(bulkResponse.items()[4].isFailed(), equalTo(true));
        assertThat(bulkResponse.items()[4].opType(), equalTo("create"));
        assertThat(bulkResponse.items()[4].index(), equalTo(getConcreteIndexName()));
        assertThat(bulkResponse.items()[4].type(), equalTo("type1"));

        RefreshResponse refreshResponse = client1.admin().indices().prepareRefresh("test").execute().actionGet();
        assertThat(refreshResponse.successfulShards(), equalTo(10));
        assertThat(refreshResponse.failedShards(), equalTo(0));
View Full Code Here

                    builder.endObject();

                    request.add(Requests.indexRequest("test").type("type1").id(Integer.toString(counter))
                            .source(builder));
                }
                BulkResponse response = request.execute().actionGet();
                if (response.hasFailures()) {
                    System.err.println("--> failures...");
                }
                if (((i * BATCH) % 10000) == 0) {
                    System.out.println("--> Indexed " + (i * BATCH) + " took " + stopWatch.stop().lastTaskTime());
                    stopWatch.start();
View Full Code Here

                    builder.endObject();

                    request.add(Requests.indexRequest("test").type("type1").id(Integer.toString(counter))
                            .source(builder));
                }
                BulkResponse response = request.execute().actionGet();
                if (response.hasFailures()) {
                    System.err.println("--> failures...");
                }
                if (((i * BATCH) % 10000) == 0) {
                    System.out.println("--> Indexed " + (i * BATCH) + " took " + stopWatch.stop().lastTaskTime());
                    stopWatch.start();
View Full Code Here

            // its ok
        }
        client.admin().indices().prepareCreate("test").execute().actionGet();
        client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();

        BulkResponse bulkResponse = client.prepareBulk().add(client.prepareIndex("test", "type", "1").setSource("field1", "value1_1")).execute().actionGet();
        assertThat(bulkResponse.hasFailures(), equalTo(false));
        assertThat(bulkResponse.items().length, equalTo(1));
        IndexResponse indexResponse = bulkResponse.items()[0].response();
        assertThat(indexResponse.version(), equalTo(1l));
    }
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.