Java Code Examples for org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse#isAcknowledged()

The following examples show how to use org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse#isAcknowledged() . 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: ElasticSearchPercolateTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ElasticsearchUtil.java    From SpringBootLearn with Apache License 2.0 5 votes vote down vote up
/**
 * 删除索引
 * @param index
 * @return
 */
public static boolean deleteIndex(String index) {
    if (!isIndexExist(index)) {
        log.info("Index is not exits!");
    }
    DeleteIndexResponse dResponse = client.admin().indices().prepareDelete(index).execute().actionGet();
    if (dResponse.isAcknowledged()) {
        log.info("delete index " + index + "  successfully!");
    } else {
        log.info("Fail to delete index " + index);
    }
    return dResponse.isAcknowledged();
}
 
Example 3
Source File: IndexUtils.java    From search-spring-boot-starter with 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 4
Source File: ESOpt.java    From common-project with Apache License 2.0 5 votes vote down vote up
/**
 * 删除索引
 * @param index
 * @return
 */
public static boolean deleteIndex(String index) {
    if (!isIndexExist(index)) {
        logger.info("Index is not exits!");
    }
    DeleteIndexResponse dResponse = client.admin().indices().prepareDelete(index).execute().actionGet();
    if (dResponse.isAcknowledged()) {
        logger.info("delete index " + index + "  successfully!");
    } else {
        logger.info("Fail to delete index " + index);
    }
    return dResponse.isAcknowledged();
}
 
Example 5
Source File: ElasticsearchResource.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new elasticsearch index and adds a mapping for the document type.
 * Previously existing indexes will be removed.
 *
 * @throws Exception
 *             the exception
 */
private void createIndex() throws Exception {

	boolean exists = client.admin().indices().prepareExists(mIndex).execute().actionGet().isExists();

	// remove preexisting index
	if (exists) {
		logger.log(Level.INFO, "Preexisting index " + mIndex + " will be removed.");
		DeleteIndexResponse deleteResponse = client.admin().indices().delete(new DeleteIndexRequest(mIndex))
				.actionGet();
		if (deleteResponse.isAcknowledged()) {
			logger.log(Level.INFO, "Preexisting index " + mIndex + " successfully removed.");
			exists = false;
		}
	}

	// create schema mapping from file
	logger.log(Level.INFO, "Index " + mIndex + " will be created.");
	String docMapping = new String(Files.readAllBytes(Paths.get(documentMappingFile)));

	XContentBuilder builder = XContentFactory.jsonBuilder();
	XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(docMapping.getBytes());
	parser.close();
	builder.copyCurrentStructure(parser);

	CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(mIndex);
	createIndexRequestBuilder.addMapping(DOCUMENT_TYPE, builder);
	createIndexRequestBuilder.execute().actionGet();

}
 
Example 6
Source File: ESUpdateState.java    From sql4es with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the INDEX with the specified name 
 * @param sql
 * @param drop
 * @return
 * @throws SQLException 
 */
public int execute(String sql, DropTable drop) throws SQLException {
	String index = drop.getTableName().toString();
	index = Heading.findOriginal(sql.trim()+";", index, "table\\s+",";");
	DeleteIndexResponse response = client.admin().indices().prepareDelete(index).execute().actionGet();
	if(!response.isAcknowledged()) throw new SQLException("Elasticsearch failed to delete the specified index");
	return 0;
}
 
Example 7
Source File: ElasticBulkService.java    From mongolastic with MIT License 5 votes vote down vote up
@Override
public void dropDataSet() {
    final String indexName = config.getMisc().getDindex().getAs();
    IndicesAdminClient admin = client.getClient().admin().indices();
    IndicesExistsRequestBuilder builder = admin.prepareExists(indexName);
    if (builder.execute().actionGet().isExists()) {
        DeleteIndexResponse delete = admin.delete(new DeleteIndexRequest(indexName)).actionGet();
        if (delete.isAcknowledged())
            logger.info(String.format("The current index %s was deleted.", indexName));
        else
            logger.info(String.format("The current index %s was not deleted.", indexName));
    }
}
 
Example 8
Source File: ElasticSearchClient.java    From skywalking with Apache License 2.0 5 votes vote down vote up
protected boolean deleteIndex(String indexName, boolean formatIndexName) throws IOException {
    if (formatIndexName) {
        indexName = formatIndexName(indexName);
    }
    DeleteIndexRequest request = new DeleteIndexRequest(indexName);
    DeleteIndexResponse response;
    response = client.indices().delete(request);
    log.debug("delete {} index finished, isAcknowledged: {}", indexName, response.isAcknowledged());
    return response.isAcknowledged();
}
 
Example 9
Source File: ElasticsearchIndexManager.java    From Raigad with Apache License 2.0 5 votes vote down vote up
void deleteIndices(Client client, String indexName, int timeout) {
    DeleteIndexResponse deleteIndexResponse = client.admin().indices().prepareDelete(indexName).execute().actionGet(timeout);

    if (deleteIndexResponse.isAcknowledged()) {
        logger.info(indexName + " deleted");
    } else {
        logger.warn("Failed to delete " + indexName);
        throw new RuntimeException("Failed to delete " + indexName);
    }
}
 
Example 10
Source File: TransportClient.java    From elasticsearch-jest-example with MIT License 5 votes vote down vote up
/**
	 * 删除所有索引
	 * @param indices
	 */
	private static void deleteIndices(String indices){
		Client client = createTransportClient();
		DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indices);
		DeleteIndexResponse response = client.admin().indices().delete(deleteIndexRequest)
		        .actionGet();
		if(response.isAcknowledged()){
			System.out.println("删除成功!");
//			FlushRequest flushRequest = new FlushRequest(indices);
//			flushRequest.force(true);
//			FlushResponse flushResponse = client.admin().indices().flush(flushRequest).actionGet();
//			System.out.println(flushResponse.getTotalShards()+","+flushResponse.getSuccessfulShards()+","+flushResponse.getFailedShards());
		}
	}
 
Example 11
Source File: ElasticIndexer.java    From Stargraph with MIT License 4 votes vote down vote up
private void deleteIndex() {
    DeleteIndexResponse deleteRes = esClient.prepareDelete().get();
    if (!deleteRes.isAcknowledged()) {
        throw new IndexingException("Fail to delete old index.");
    }
}
 
Example 12
Source File: ESConnector.java    From Siamese with GNU General Public License v3.0 4 votes vote down vote up
public boolean deleteIndex(String indexName) {
	DeleteIndexRequest deleteRequest = new DeleteIndexRequest(indexName);
	DeleteIndexResponse response = client.admin().indices().delete(deleteRequest).actionGet();
	return response.isAcknowledged();
}
 
Example 13
Source File: EsIndex.java    From AsuraFramework with Apache License 2.0 2 votes vote down vote up
/**
 * 删除索引
 *
 * @param indexName
 *
 * @return
 */
public boolean deleteIndex(String indexName) {
    TransportClient client = esClientFactory.getClient();
    DeleteIndexResponse response = client.admin().indices().prepareDelete(esClientFactory.getIndexs(indexName)).execute().actionGet();
    return response.isAcknowledged();
}