org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexDelete.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    DeleteIndexRequestBuilder request = elasticsearch.get().admin().indices().prepareDelete(index);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }
    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(response -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(response)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #2
Source File: DefaultElasticSearchAdminService.java    From vertx-elasticsearch-service with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteIndex(List<String> indices, DeleteIndexOptions options, Handler<AsyncResult<Void>> resultHandler) {
    final DeleteIndexRequestBuilder builder = new DeleteIndexRequestBuilder(service.getClient(), DeleteIndexAction.INSTANCE, indices.toArray(new String[0]));

    builder.execute(new ActionListener<DeleteIndexResponse>() {
        @Override
        public void onResponse(DeleteIndexResponse deleteIndexResponse) {
            resultHandler.handle(Future.succeededFuture());
        }

        @Override
        public void onFailure(Exception e) {
            resultHandler.handle(Future.failedFuture(e));
        }
    });
}
 
Example #3
Source File: SimpleTest.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    try {
        DeleteIndexRequestBuilder deleteIndexRequestBuilder = new DeleteIndexRequestBuilder(client("1"), DeleteIndexAction.INSTANCE, "test");
        deleteIndexRequestBuilder.execute().actionGet();
    } catch (Exception e) {
        // ignore
    }
    IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client("1"), IndexAction.INSTANCE);
    indexRequestBuilder
            .setIndex("test")
            .setType("test")
            .setId("1")
            .setSource(jsonBuilder().startObject().field("field", "1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8").endObject())
            .setRefresh(true)
            .execute()
            .actionGet();
    String doc = client("1").prepareSearch("test")
            .setTypes("test")
            .setQuery(matchQuery("field", "1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8"))
            .execute()
            .actionGet()
            .getHits().getAt(0).getSourceAsString();

    assertEquals(doc, "{\"field\":\"1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8\"}");
}
 
Example #4
Source File: HttpBulkNodeClient.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
@Override
public HttpBulkNodeClient deleteIndex(String index) {
    if (closed) {
        throw new ElasticsearchException("client is closed");
    }
    if (client == null) {
        logger.warn("no client");
        return this;
    }
    if (index == null) {
        logger.warn("no index name given to delete index");
        return this;
    }
    DeleteIndexRequestBuilder deleteIndexRequestBuilder =
            new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, index);
    deleteIndexRequestBuilder.execute().actionGet();
    return this;
}
 
Example #5
Source File: BulkNodeClient.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
@Override
public BulkNodeClient deleteIndex(String index) {
    if (closed) {
        throw new ElasticsearchException("client is closed");
    }
    if (client == null) {
        logger.warn("no client");
        return this;
    }
    if (index == null) {
        logger.warn("no index name given to delete index");
        return this;
    }
    DeleteIndexRequestBuilder deleteIndexRequestBuilder =
            new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, index);
    deleteIndexRequestBuilder.execute().actionGet();
    return this;
}
 
Example #6
Source File: TransportWriterVariant.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public TestClient getTestClient(Config config)
    throws IOException {
  final ElasticsearchTransportClientWriter transportClientWriter = new ElasticsearchTransportClientWriter(config);
  final TransportClient transportClient = transportClientWriter.getTransportClient();
  return new TestClient() {
    @Override
    public GetResponse get(GetRequest getRequest)
        throws IOException {
      try {
        return transportClient.get(getRequest).get();
      } catch (Exception e) {
        throw new IOException(e);
      }
    }

    @Override
    public void recreateIndex(String indexName)
        throws IOException {
      DeleteIndexRequestBuilder dirBuilder = transportClient.admin().indices().prepareDelete(indexName);
      try {
        DeleteIndexResponse diResponse = dirBuilder.execute().actionGet();
      } catch (IndexNotFoundException ie) {
        System.out.println("Index not found... that's ok");
      }

      CreateIndexRequestBuilder cirBuilder = transportClient.admin().indices().prepareCreate(indexName);
      CreateIndexResponse ciResponse = cirBuilder.execute().actionGet();
      Assert.assertTrue(ciResponse.isAcknowledged(), "Create index succeeeded");
    }

    @Override
    public void close()
        throws IOException {
      transportClientWriter.close();
    }
  };
}
 
Example #7
Source File: ElasticsearchClusterRunner.java    From elasticsearch-cluster-runner with Apache License 2.0 5 votes vote down vote up
public AcknowledgedResponse deleteIndex(final String index, final BuilderCallback<DeleteIndexRequestBuilder> builder) {
    final AcknowledgedResponse actionGet = builder.apply(client().admin().indices().prepareDelete(index)).execute().actionGet();
    if (!actionGet.isAcknowledged()) {
        onFailure("Failed to create " + index + ".", actionGet);
    }
    return actionGet;
}
 
Example #8
Source File: LangDetectBinaryTests.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 5 votes vote down vote up
public void testLangDetectBinary() throws Exception {
    try {
        CreateIndexRequestBuilder createIndexRequestBuilder =
                new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE).setIndex("test");
        createIndexRequestBuilder.addMapping("someType", jsonBuilder()
                .startObject()
                .startObject("properties")
                .startObject("content")
                .field("type", "binary")
                .startObject("fields")
                .startObject("language")
                .field("type", "langdetect")
                .field("binary", true)
                .endObject()
                .endObject()
                .endObject()
                .endObject()
                .endObject());
        createIndexRequestBuilder.execute().actionGet();
        IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client(), IndexAction.INSTANCE)
                .setIndex("test").setType("someType").setId("1")
                //\"God Save the Queen\" (alternatively \"God Save the King\"
                .setSource("content", "IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg==");
        indexRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
                .execute().actionGet();
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client(), SearchAction.INSTANCE)
                .setIndices("test")
                .setQuery(QueryBuilders.termQuery("content.language", "en"))
                .addStoredField("content.language");
        SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
        assertEquals(1L, searchResponse.getHits().getTotalHits());
        assertEquals("en", searchResponse.getHits().getAt(0).field("content.language").getValue());
    } finally {
        DeleteIndexRequestBuilder deleteIndexRequestBuilder =
                new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, "test");
        deleteIndexRequestBuilder.execute().actionGet();
    }
}
 
Example #9
Source File: BaseMetricTransportClient.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized BaseMetricTransportClient deleteIndex(String index) {
    if (client == null) {
        logger.warn("no client for delete index");
        return this;
    }
    if (index == null) {
        logger.warn("no index name given to delete index");
        return this;
    }
    new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, index).execute().actionGet();
    return this;
}
 
Example #10
Source File: ElasticsearchAssertions.java    From crate with Apache License 2.0 4 votes vote down vote up
public static void assertAcked(DeleteIndexRequestBuilder builder) {
    assertAcked(builder.get());
}
 
Example #11
Source File: ElasticClient.java    From Stargraph with MIT License 4 votes vote down vote up
DeleteIndexRequestBuilder prepareDelete() {
    logger.info(marker, "Deleting {}", kbId);
    return client.admin().indices().prepareDelete(getIndexName());
}
 
Example #12
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteIndexRequestBuilder prepareDelete(String... indices) {
    return new DeleteIndexRequestBuilder(this, DeleteIndexAction.INSTANCE, indices);
}
 
Example #13
Source File: LangDetectGermanTests.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 4 votes vote down vote up
public void testGermanLanguageCode() throws Exception {
    try {
        XContentBuilder builder = jsonBuilder()
                .startObject()
                .startObject("properties")
                .startObject("content")
                .field("type", "text")
                .startObject("fields")
                .startObject("language")
                .field("type", "langdetect")
                .array("languages", "zh-cn", "en", "de")
                .endObject()
                .endObject()
                .endObject()
                .endObject()
                .endObject();
        CreateIndexRequestBuilder createIndexRequestBuilder =
                new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE);
        createIndexRequestBuilder.setIndex("test").addMapping("someType", builder).execute().actionGet();
        String source = "Einigkeit und Recht und Freiheit\n" +
                "für das deutsche Vaterland!\n" +
                "Danach lasst uns alle streben\n" +
                "brüderlich mit Herz und Hand!";
        IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client(), IndexAction.INSTANCE)
                .setIndex("test").setType("someType").setId("1")
                .setSource("content", source);
        indexRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
                .execute().actionGet();
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client(), SearchAction.INSTANCE)
                .setIndices("test")
                .setQuery(QueryBuilders.termQuery("content.language", "de"))
                .addStoredField("content.language");
        SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
        assertEquals(1L, searchResponse.getHits().getTotalHits());
        assertEquals("de", searchResponse.getHits().getAt(0).field("content.language").getValue());
    } finally {
        DeleteIndexRequestBuilder deleteIndexRequestBuilder =
                new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, "test");
        deleteIndexRequestBuilder.execute().actionGet();
    }
}
 
Example #14
Source File: LangDetectChineseTests.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 4 votes vote down vote up
public void testChineseLanguageCode() throws Exception {
    try {
        XContentBuilder builder = jsonBuilder()
                .startObject()
                .startObject("properties")
                .startObject("content")
                .field("type", "text")
                .startObject("fields")
                .startObject("language")
                .field("type", "langdetect")
                .array("languages", "zh-cn", "en", "de")
                .endObject()
                .endObject()
                .endObject()
                .endObject()
                .endObject();
        CreateIndexRequestBuilder createIndexRequestBuilder =
                new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE);
        createIndexRequestBuilder.setIndex("test").addMapping("someType", builder).execute().actionGet();
        String source = "位于美国首都华盛顿都会圈的希望中文学校5日晚举办活动庆祝建立20周年。" +
                "从中国大陆留学生为子女学中文而自发建立的学习班,到学生规模在全美名列前茅的中文学校," +
                "这个平台的发展也折射出美国的中文教育热度逐步提升。\n" +
                "希望中文学校是大华盛顿地区最大中文学校,现有7个校区逾4000名学生," +
                "规模在美国东部数一数二。" +
                "不过,见证了希望中文学校20年发展的人们起初根本无法想象这个小小的中文教育平台能发展到今日之规模。";
        IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client(), IndexAction.INSTANCE)
                .setIndex("test").setType("someType").setId("1")
                .setSource("content", source);
        indexRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
                .execute().actionGet();
        SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client(), SearchAction.INSTANCE)
                .setIndices("test")
                .setQuery(QueryBuilders.termQuery("content.language", "zh-cn"))
                .addStoredField("content.language");
        SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
        assertEquals(1L, searchResponse.getHits().getTotalHits());
        assertEquals("zh-cn", searchResponse.getHits().getAt(0).field("content.language").getValue());
    } finally {
        DeleteIndexRequestBuilder deleteIndexRequestBuilder =
                new DeleteIndexRequestBuilder(client(), DeleteIndexAction.INSTANCE, "test");
        deleteIndexRequestBuilder.execute().actionGet();
    }
}
 
Example #15
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteIndexRequestBuilder prepareDelete(String... indices) {
    return new DeleteIndexRequestBuilder(this, DeleteIndexAction.INSTANCE, indices);
}
 
Example #16
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Deletes an index based on the index name.
 *
 * @param indices The indices to delete. Use "_all" to delete all indices.
 */
DeleteIndexRequestBuilder prepareDelete(String... indices);
 
Example #17
Source File: IndicesAdminClient.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Deletes an index based on the index name.
 *
 * @param indices The indices to delete. Use "_all" to delete all indices.
 */
DeleteIndexRequestBuilder prepareDelete(String... indices);