Java Code Examples for org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest

The following examples show how to use org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest. These examples are extracted from open source projects. 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 Project: blog-sample   Source File: IndexController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 删除索引
 * @param index 索引名
 * @author jitwxs
 * @since 2018/10/9 15:08
 */
@DeleteMapping("/index/delete/{index}")
public ResultBean deleteIndex(@PathVariable String index) {
    if (StringUtils.isBlank(index)) {
        return ResultBean.error("参数错误,索引为空!");
    }
    try {
        // 删除索引
        DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(index);
        DeleteIndexResponse response = transportClient.admin().indices().delete(deleteIndexRequest).get();

        logger.info("删除索引结果:{}",response.isAcknowledged());
        return ResultBean.success("删除索引成功!");
    } catch (Exception e) {
        logger.error("删除索引失败!要删除的索引为{},异常为:",index,e.getMessage(),e);
        return ResultBean.error("删除索引失败!");
    }
}
 
Example 2
Source Project: Elasticsearch   Source File: TableCreator.java    License: Apache License 2.0 6 votes vote down vote up
private void deleteOrphans(final CreateTableResponseListener listener, final CreateTableAnalyzedStatement statement) {
    if (clusterService.state().metaData().hasAlias(statement.tableIdent().fqn())
        && PartitionName.isPartition(
            clusterService.state().metaData().getAliasAndIndexLookup().get(statement.tableIdent().fqn()).getIndices().iterator().next().getIndex())) {
        logger.debug("Deleting orphaned partitions with alias: {}", statement.tableIdent().fqn());
        transportActionProvider.transportDeleteIndexAction().execute(new DeleteIndexRequest(statement.tableIdent().fqn()), new ActionListener<DeleteIndexResponse>() {
            @Override
            public void onResponse(DeleteIndexResponse response) {
                if (!response.isAcknowledged()) {
                    warnNotAcknowledged("deleting orphaned alias");
                }
                deleteOrphanedPartitions(listener, statement.tableIdent());
            }

            @Override
            public void onFailure(Throwable e) {
                listener.onFailure(e);
            }
        });
    } else {
        deleteOrphanedPartitions(listener, statement.tableIdent());
    }
}
 
Example 3
Source Project: Elasticsearch   Source File: TableCreator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * if some orphaned partition with the same table name still exist,
 * delete them beforehand as they would create unwanted and maybe invalid
 * initial data.
 *
 * should never delete partitions of existing partitioned tables
 */
private void deleteOrphanedPartitions(final CreateTableResponseListener listener, TableIdent tableIdent) {
    String partitionWildCard = PartitionName.templateName(tableIdent.schema(), tableIdent.name()) + "*";
    String[] orphans = indexNameExpressionResolver.concreteIndices(clusterService.state(), IndicesOptions.strictExpand(), partitionWildCard);
    if (orphans.length > 0) {
        if (logger.isDebugEnabled()) {
            logger.debug("Deleting orphaned partitions: {}", Joiner.on(", ").join(orphans));
        }
        transportActionProvider.transportDeleteIndexAction().execute(new DeleteIndexRequest(orphans), new ActionListener<DeleteIndexResponse>() {
            @Override
            public void onResponse(DeleteIndexResponse response) {
                if (!response.isAcknowledged()) {
                    warnNotAcknowledged("deleting orphans");
                }
                listener.onResponse(SUCCESS_RESULT);
            }

            @Override
            public void onFailure(Throwable e) {
                listener.onFailure(e);
            }
        });
    } else {
        listener.onResponse(SUCCESS_RESULT);
    }
}
 
Example 4
Source Project: conductor   Source File: TestElasticSearchDAOV5.java    License: Apache License 2.0 6 votes vote down vote up
private void deleteAllIndices() {

		ImmutableOpenMap<String, IndexMetaData> indices = elasticSearchClient.admin().cluster()
				.prepareState().get().getState()
				.getMetaData().getIndices();

		indices.forEach(cursor -> {
			try {
				elasticSearchClient.admin()
						.indices()
						.delete(new DeleteIndexRequest(cursor.value.getIndex().getName()))
						.get();
			} catch (InterruptedException | ExecutionException e) {
				throw new RuntimeException(e);
			}
		});
	}
 
Example 5
Source Project: javabase   Source File: UpdateMappingFieldDemo.java    License: Apache License 2.0 6 votes vote down vote up
private static void update() {
    try {
        IndicesAdminClient indicesAdminClient = client.admin().indices();
        if (indicesAdminClient.prepareExists(INDEX_NAME_v2).execute().actionGet().isExists()) {
            indicesAdminClient.delete(new DeleteIndexRequest(INDEX_NAME_v2)).actionGet();
        }
        indicesAdminClient.prepareCreate(INDEX_NAME_v2).addMapping(INDEX_TYPE,getItemInfoMapping()).execute().actionGet();
        //等待集群shard,防止No shard available for 异常
        ClusterAdminClient clusterAdminClient = client.admin().cluster();
        clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000);
        //0、更新mapping
        updateMapping();
        //1、更新数据
        reindexData(indicesAdminClient);

        //2、realias 重新建立连接
       indicesAdminClient.prepareAliases().removeAlias(INDEX_NAME_v1, ALIX_NAME).addAlias(INDEX_NAME_v2, ALIX_NAME).execute().actionGet();
    }catch (Exception e){
        log.error("beforeUpdate error:{}"+e.getLocalizedMessage());
    }

}
 
Example 6
Source Project: javabase   Source File: UpdateMappingFieldDemo.java    License: Apache License 2.0 6 votes vote down vote up
private static void beforeUpdate()  {
    try {
        IndicesAdminClient indicesAdminClient = client.admin().indices();
        indicesAdminClient.delete(new DeleteIndexRequest(INDEX_NAME_v1)).actionGet();
        if (!indicesAdminClient.prepareExists(INDEX_NAME_v1).execute().actionGet().isExists()) {
            indicesAdminClient.prepareCreate(INDEX_NAME_v1).addMapping(INDEX_TYPE,getItemInfoMapping()).execute().actionGet();
        }
        //等待集群shard,防止No shard available for 异常
        ClusterAdminClient clusterAdminClient = client.admin().cluster();
        clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000);
        //创建别名alias
        indicesAdminClient.prepareAliases().addAlias(INDEX_NAME_v1, ALIX_NAME).execute().actionGet();
        prepareData(indicesAdminClient);
    }catch (Exception e){
        log.error("beforeUpdate error:{}"+e.getLocalizedMessage());
    }
}
 
Example 7
Source Project: es-service-parent   Source File: IndexTransaction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 删除索引
 * 
 * @param index_type
 */
public boolean deleteIndex(String index_type) {
    try {
        AdminClient adminClient = ESClient.getClient().admin();
        if (adminClient.indices().prepareExists(index_type).execute().actionGet().isExists()) {
            ESClient.getClient().admin().indices().delete(new DeleteIndexRequest(index_type));
        }
        if (adminClient.indices().prepareExists(index_type + "_1").execute().actionGet()
                .isExists()) {
            ESClient.getClient().admin().indices()
                    .delete(new DeleteIndexRequest(index_type + "_1"));
        }
        if (adminClient.indices().prepareExists(index_type + "_2").execute().actionGet()
                .isExists()) {
            ESClient.getClient().admin().indices()
                    .delete(new DeleteIndexRequest(index_type + "_2"));
        }
        return true;
    } catch (Exception e) {
        log.error("delete index fail,indexname:{}", index_type);
    }
    return false;
}
 
Example 8
Source Project: vertexium   Source File: Elasticsearch5SearchIndex.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void drop(Graph graph) {
    this.indexInfosLock.writeLock().lock();
    try {
        if (this.indexInfos == null) {
            loadIndexInfos();
        }
        Set<String> indexInfosSet = new HashSet<>(this.indexInfos.keySet());
        for (String indexName : indexInfosSet) {
            try {
                DeleteIndexRequest deleteRequest = new DeleteIndexRequest(indexName);
                getClient().admin().indices().delete(deleteRequest).actionGet();
            } catch (Exception ex) {
                throw new VertexiumException("Could not delete index " + indexName, ex);
            }
            this.indexInfos.remove(indexName);
            initializeIndex(indexName);
        }
    } finally {
        this.indexInfosLock.writeLock().unlock();
    }
}
 
Example 9
Source Project: zeppelin   Source File: ElasticsearchInterpreterTest.java    License: Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void clean() {
  if (transportInterpreter != null) {
    transportInterpreter.close();
  }

  if (httpInterpreter != null) {
    httpInterpreter.close();
  }

  if (elsClient != null) {
    elsClient.admin().indices().delete(new DeleteIndexRequest("*")).actionGet();
    elsClient.close();
  }

  if (elsNode != null) {
    elsNode.close();
  }
}
 
Example 10
@After
public void cleanup() throws IOException
{
  try {
    DeleteIndexResponse delete = store.client.admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).actionGet();
    if (!delete.isAcknowledged()) {
      logger.error("Index wasn't deleted");
    }

    store.disconnect();
  } catch (NoNodeAvailableException e) {
    //This indicates that elasticsearch is not running on a particular machine.
    //Silently ignore in this case.
  }

}
 
Example 11
Source Project: elasticsearch-xml   Source File: XmlPluginTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBigAndFatResponse() throws Exception {
    Client client = client("1");
    for (int i = 0; i < 10000; i++) {
        client.index(new IndexRequest("test", "test", Integer.toString(i))
                .source("{\"random\":\""+randomString(32)+ " " + randomString(32) + "\"}")).actionGet();
    }
    client.admin().indices().refresh(new RefreshRequest("test")).actionGet();
    InetSocketTransportAddress httpAddress = findHttpAddress(client);
    if (httpAddress == null) {
        throw new IllegalArgumentException("no HTTP address found");
    }
    URL base = new URL("http://" + httpAddress.getHost() + ":" + httpAddress.getPort());
    URL url = new URL(base, "/test/test/_search?xml&pretty&size=10000");
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    int count = 0;
    String line;
    while ((line = reader.readLine()) != null) {
        count += line.length();
    }
    assertTrue(count >= 2309156);
    reader.close();
    client.admin().indices().delete(new DeleteIndexRequest("test"));
}
 
Example 12
Source Project: streams   Source File: ElasticsearchPersistWriterIT.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void prepareTestPersistWriter() throws Exception {

  testConfiguration = new ComponentConfigurator<>(ElasticsearchWriterConfiguration.class).detectConfiguration("ElasticsearchPersistWriterIT");
  testClient = ElasticsearchClientManager.getInstance(testConfiguration).client();

  ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
  ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
  assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);

  IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getIndex());
  IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
  if(indicesExistsResponse.isExists()) {
    DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getIndex());
    DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
    assertTrue(deleteIndexResponse.isAcknowledged());
  }

}
 
Example 13
Source Project: crate   Source File: DeleteAllPartitions.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier executor,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {
    if (partitions.isEmpty()) {
        consumer.accept(InMemoryBatchIterator.of(new Row1(0L), SentinelRow.SENTINEL), null);
    } else {
        /*
         * table is partitioned, in case of concurrent "delete from partitions"
         * it could be that some partitions are already deleted,
         * so ignore it if some are missing
         */
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(partitions().toArray(new String[0]))
            .indicesOptions(IndicesOptions.lenientExpandOpen());
        executor.transportActionProvider().transportDeleteIndexAction().execute(
            deleteIndexRequest,
            new OneRowActionListener<>(consumer, r -> Row1.ROW_COUNT_UNKNOWN)
        );
    }
}
 
Example 14
Source Project: streams   Source File: HdfsElasticsearchIT.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void prepareTest() throws Exception {

  testConfiguration = new StreamsConfigurator<>(HdfsElasticsearchConfiguration.class).detectCustomConfiguration("HdfsElasticsearchIT");
  testClient = ElasticsearchClientManager.getInstance(testConfiguration.getDestination()).client();

  ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
  ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
  assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);

  IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getDestination().getIndex());
  IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
  if(indicesExistsResponse.isExists()) {
    DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getDestination().getIndex());
    DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
    assertTrue(deleteIndexResponse.isAcknowledged());
  };
}
 
Example 15
Source Project: streams   Source File: TwitterHistoryElasticsearchIT.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void prepareTest() throws Exception {

  testConfiguration = new StreamsConfigurator<>(TwitterHistoryElasticsearchConfiguration.class).detectCustomConfiguration();

  testClient = ElasticsearchClientManager.getInstance(testConfiguration.getElasticsearch()).client();

  ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
  ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
  assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);

  IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getElasticsearch().getIndex());
  IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();

  if(indicesExistsResponse.isExists()) {
    DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getElasticsearch().getIndex());
    DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
    assertTrue(deleteIndexResponse.isAcknowledged());
  };
}
 
Example 16
Source Project: crate   Source File: DeletePlanner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier executor,
    PlannerContext plannerContext,
    RowConsumer consumer,
    Row params,
    SubQueryResults subQueryResults) {

    WhereClause where = detailedQuery.toBoundWhereClause(
        table.tableInfo(),
        executor.functions(),
        params,
        subQueryResults,
        plannerContext.transactionContext()
    );
    if (!where.partitions().isEmpty() && !where.hasQuery()) {
        DeleteIndexRequest request = new DeleteIndexRequest(where.partitions().toArray(new String[0]));
        request.indicesOptions(IndicesOptions.lenientExpandOpen());
        executor.transportActionProvider().transportDeleteIndexAction()
            .execute(request, new OneRowActionListener<>(consumer, o -> new Row1(-1L)));
        return;
    }

    ExecutionPlan executionPlan = deleteByQuery(table, plannerContext, where);
    NodeOperationTree nodeOpTree = NodeOperationTreeGenerator.fromPlan(executionPlan, executor.localNodeId());
    executor.phasesTaskFactory()
        .create(plannerContext.jobId(), Collections.singletonList(nodeOpTree))
        .execute(consumer, plannerContext.transactionContext());
}
 
Example 17
Source Project: search-spring-boot-starter   Source File: IndexUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean deleteIndex(Client client, String index) throws InterruptedException, ExecutionException {
    if (isExistsIndex(client, index)) {
        DeleteIndexResponse deleteResponse = client.admin().indices().delete(new DeleteIndexRequest(index)).get();
        return deleteResponse.isAcknowledged();
    } else {
        return false;
    }
}
 
Example 18
Source Project: elasticshell   Source File: DeleteIndexRequestBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(DeleteIndexRequest request, DeleteIndexResponse response, XContentBuilder builder) throws IOException {
    return builder.startObject()
            .field(Fields.OK, true)
            .field(Fields.ACKNOWLEDGED, response.isAcknowledged())
            .endObject();
}
 
Example 19
Source Project: blue-marlin   Source File: TestBase.java    License: Apache License 2.0 5 votes vote down vote up
public void clearBookings() throws IOException, JSONException
{
    try
    {
        this.rhlclient.indices().delete(new DeleteIndexRequest().indices(this.bookingsIndex));
        this.rhlclient.indices().delete(new DeleteIndexRequest().indices(this.bookingBucketsIndex));
    }
    catch (Exception e)
    {
        //Throws exception if the there is no index
    }

    putDocIntoIndex("/bookings/bookingSample.json", this.bookingsIndex);
    putDocIntoIndex("/bookings/bookingBucketSample.json", this.bookingBucketsIndex);
}
 
Example 20
@AfterClass
public static void stopElasticsearchContainerAndClient() throws IOException {
    client.indices().delete(new DeleteIndexRequest(INDEX), RequestOptions.DEFAULT);
    container.stop();
    client.close();

    try {
        realReporter.flush().get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example 21
@Test
public void testTryToDeleteNonExistingIndex() throws IOException {
    ElasticsearchStatusException ese = null;
    try {
        client.indices().delete(new DeleteIndexRequest(SECOND_INDEX), RequestOptions.DEFAULT);
    } catch (ElasticsearchStatusException e) {
        ese = e;
    }
    assertThat(ese).isNotNull();
    assertThat(ese.status().getStatus()).isEqualTo(404);
}
 
Example 22
@Test
public void testCreateAndDeleteIndex() throws IOException, ExecutionException, InterruptedException {
    // Create an Index
    doCreateIndex(new CreateIndexRequest(SECOND_INDEX));

    validateSpanContentAfterIndexCreateRequest();
    // Delete the index
    reporter.reset();

    doDeleteIndex(new DeleteIndexRequest(SECOND_INDEX));

    validateSpanContentAfterIndexDeleteRequest();
}
 
Example 23
protected AcknowledgedResponse doDeleteIndex(DeleteIndexRequest deleteIndexRequest) throws IOException, ExecutionException, InterruptedException {
    if (async) {
        ClientMethod<DeleteIndexRequest, AcknowledgedResponse> method =
            (request, options, listener) -> client.indices().deleteAsync(request, options, listener);
        return invokeAsync(deleteIndexRequest, method);
    }
    return client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
}
 
Example 24
Source Project: logging-log4j2   Source File: LogstashIT.java    License: Apache License 2.0 5 votes vote down vote up
private static RestHighLevelClient createClient() throws IOException {

        // Instantiate the client.
        LOGGER.info("instantiating the ES client");
        final HttpHost httpHost = new HttpHost(HOST_NAME, MavenHardcodedConstants.ES_PORT);
        final RestClientBuilder clientBuilder =
                RestClient.builder(httpHost);
        final RestHighLevelClient client = new RestHighLevelClient(clientBuilder);

        // Verify the connection.
        LOGGER.info("verifying the ES connection");
        final ClusterHealthResponse healthResponse = client
                .cluster()
                .health(new ClusterHealthRequest(), RequestOptions.DEFAULT);
        Assertions
                .assertThat(healthResponse.getStatus())
                .isNotEqualTo(ClusterHealthStatus.RED);

        // Delete the index.
        LOGGER.info("deleting the ES index");
        final DeleteIndexRequest deleteRequest =
                new DeleteIndexRequest(MavenHardcodedConstants.ES_INDEX_NAME);
        try {
            final AcknowledgedResponse deleteResponse = client
                    .indices()
                    .delete(deleteRequest, RequestOptions.DEFAULT);
            Assertions
                    .assertThat(deleteResponse.isAcknowledged())
                    .isTrue();
        } catch (ElasticsearchStatusException error) {
            Assertions.assertThat(error)
                    .satisfies(ignored -> Assertions
                            .assertThat(error.status())
                            .isEqualTo(RestStatus.NOT_FOUND));
        }

        return client;

    }
 
Example 25
Source Project: java-11-examples   Source File: DataServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<AcknowledgedResponse> deleteIndex(String indexName) {
    try {
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName);
        AcknowledgedResponse deleteResponse = client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
        return Optional.of(deleteResponse);
    } catch (IOException e) {
        return Optional.empty();
    }
}
 
Example 26
Source Project: java-study   Source File: EsHighLevelRestTest1.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 删除索引
 *
 * @throws IOException
 */
private static void deleteIndex() throws IOException {
	String index = "userindex";
	DeleteIndexRequest  request = new DeleteIndexRequest(index);
	// 同步删除
	client.indices().delete(request,RequestOptions.DEFAULT);
	System.out.println("删除索引库成功!"+index);

}
 
Example 27
Source Project: arctic-sea   Source File: ElasticsearchAwareTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws InterruptedException, IOException {
    try {
        logger.info("Deleting {} index", clientSettings.getIndexId());
        Thread.sleep(2000);
        getEmbeddedClient().indices()
                .delete(new DeleteIndexRequest(clientSettings.getIndexId()), RequestOptions.DEFAULT)
                .isAcknowledged();
        Thread.sleep(2000);
    } catch (ElasticsearchException e) {
    }
    setUpHook();
}
 
Example 28
Source Project: Elasticsearch   Source File: DropTableTask.java    License: Apache License 2.0 5 votes vote down vote up
private void deleteESIndex(String indexOrAlias) {
    DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexOrAlias);
    deleteIndexRequest.putHeader(LoginUserContext.USER_INFO_KEY, this.getParamContext().getLoginUserContext());
    if (tableInfo.isPartitioned()) {
        deleteIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
    }
    deleteIndexAction.execute(deleteIndexRequest, new ActionListener<DeleteIndexResponse>() {
        @Override
        public void onResponse(DeleteIndexResponse response) {
            if (!response.isAcknowledged()) {
                warnNotAcknowledged(String.format(Locale.ENGLISH, "dropping table '%s'", tableInfo.ident().fqn()));
            }
            result.set(SUCCESS_RESULT);
        }

        @Override
        public void onFailure(Throwable e) {
            if (tableInfo.isPartitioned()) {
                logger.warn("Could not (fully) delete all partitions of {}. " +
                        "Some orphaned partitions might still exist, " +
                        "but are not accessible.", e, tableInfo.ident().fqn());
            }
            if (ifExists && e instanceof IndexNotFoundException) {
                result.set(TaskResult.ZERO);
            } else {
                result.setException(e);
            }
        }
    });
}
 
Example 29
Source Project: elasticsearch-gatherer   Source File: AbstractNodeTest.java    License: Apache License 2.0 5 votes vote down vote up
@AfterMethod
public void deleteIndices() {
    logger.info("deleting index {}", INDEX);
    try {
        client("1").admin().indices().delete(new DeleteIndexRequest().indices(INDEX)).actionGet();
    } catch (IndexMissingException e) {
        // ignore
    }
    logger.info("index {} deleted", INDEX);
    closeAllNodes();
}
 
Example 30
Source Project: Elasticsearch   Source File: RestDeleteIndexAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
    deleteIndexRequest.timeout(request.paramAsTime("timeout", deleteIndexRequest.timeout()));
    deleteIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteIndexRequest.masterNodeTimeout()));
    deleteIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteIndexRequest.indicesOptions()));
    client.admin().indices().delete(deleteIndexRequest, new AcknowledgedRestListener<DeleteIndexResponse>(channel));
}