Exemplo n.º 1
0
  @Test
  public void testDeleteAllOneIndex() {
    client.admin().indices().prepareDelete().execute().actionGet();

    String json =
        "{"
            + "\"user\":\"kimchy\","
            + "\"postDate\":\"2013-01-30\","
            + "\"message\":\"trying out Elastic Search\""
            + "}";

    client.prepareIndex("twitter", "tweet").setSource(json).setRefresh(true).execute().actionGet();

    SearchResponse search =
        client.prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
    assertThat(search.getHits().totalHits(), equalTo(1l));
    DeleteByQueryRequestBuilder deleteByQueryRequestBuilder =
        new DeleteByQueryRequestBuilder(client);
    deleteByQueryRequestBuilder.setQuery(QueryBuilders.matchAllQuery());

    DeleteByQueryResponse actionGet = deleteByQueryRequestBuilder.execute().actionGet();
    assertThat(actionGet.getIndex("twitter"), notNullValue());
    assertThat(actionGet.getIndex("twitter").getFailedShards(), equalTo(0));

    client.admin().indices().prepareRefresh().execute().actionGet();
    search = client.prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
    assertThat(search.getHits().totalHits(), equalTo(0l));
  }
Exemplo n.º 2
0
 @Test
 public void testDeleteAllNoIndices() {
   client.admin().indices().prepareDelete().execute().actionGet();
   client.admin().indices().prepareRefresh().execute().actionGet();
   DeleteByQueryRequestBuilder deleteByQueryRequestBuilder =
       new DeleteByQueryRequestBuilder(client);
   deleteByQueryRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
   DeleteByQueryResponse actionGet = deleteByQueryRequestBuilder.execute().actionGet();
   assertThat(actionGet.getIndices().size(), equalTo(0));
 }
  private void clearDocuments() {

    if (isAnyIndexPresent()) {

      DeleteByQueryRequestBuilder deleteByQueryRequestBuilder =
          new DeleteByQueryRequestBuilder(client);
      deleteByQueryRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
      deleteByQueryRequestBuilder.execute().actionGet();

      refreshNode();
    }
  }