use of org.elasticsearch.client.IndicesAdminClient in project beam by apache.
the class ElasticSearchIOTestUtils method deleteIndex.
/** Deletes the given index synchronously. */
static void deleteIndex(String index, Client client) throws Exception {
IndicesAdminClient indices = client.admin().indices();
IndicesExistsResponse indicesExistsResponse = indices.exists(new IndicesExistsRequest(index)).get();
if (indicesExistsResponse.isExists()) {
indices.prepareClose(index).get();
indices.delete(Requests.deleteIndexRequest(index)).get();
}
}
use of org.elasticsearch.client.IndicesAdminClient in project fess by codelibs.
the class AdminUpgradeAction method upgradeFromAll.
private void upgradeFromAll() {
final IndicesAdminClient indicesClient = fessEsClient.admin().indices();
final String crawlerIndex = fessConfig.getIndexDocumentCrawlerIndex();
// .crawler
if (existsIndex(indicesClient, crawlerIndex, IndicesOptions.fromOptions(false, true, true, true))) {
deleteIndex(indicesClient, crawlerIndex, response -> {
});
}
}
use of org.elasticsearch.client.IndicesAdminClient in project fabric8 by jboss-fuse.
the class AbstractElasticsearchStorage method putInsightTemplate.
protected void putInsightTemplate(String indexTemplateLocation) {
IndicesAdminClient indicesAdminClient = getNode().client().admin().indices();
InputStream stream = null;
try {
stream = new URL(indexTemplateLocation).openStream();
} catch (IOException e) {
throw new IllegalArgumentException("Unable to load Elastic Search index defined at this location: " + indexTemplateLocation);
}
String templateText = new Scanner(stream, "UTF-8").useDelimiter("\\A").next();
PutIndexTemplateRequest putInsightTemplateRequest = new PutIndexTemplateRequestBuilder(indicesAdminClient, "insight").setSource(templateText).request();
indicesAdminClient.putTemplate(putInsightTemplateRequest).actionGet();
}
use of org.elasticsearch.client.IndicesAdminClient in project ecs-dashboard by carone1.
the class ElasticIndexCleaner method truncateOldIndexes.
public static void truncateOldIndexes(TransportClient elasticClient, Date thresholdDate, String indexName, String indexType) {
List<String> indexesToDelete = new ArrayList<String>();
ImmutableOpenMap<String, IndexMetaData> indices = elasticClient.admin().cluster().prepareState().get().getState().getMetaData().getIndices();
Iterator<String> itr = indices.keysIt();
while (itr.hasNext()) {
String idxName = itr.next();
// only process index that are matching the main index name
if (idxName.startsWith(indexName)) {
// stripping out index name portion
String dateString = idxName.replaceAll(indexName + "-", "");
// assumption: string is following this format YYYY-MM-DD
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
// create date out of the constructed date
Date indexDate = sdf.parse(dateString);
// than threshold date
if (indexDate.before(thresholdDate) || indexDate.equals(thresholdDate)) {
// Looks like this index is older than our
// threshold date
// index is marked for deletion deletion
indexesToDelete.add(idxName);
}
} catch (ParseException e) {
LOGGER.error("Issue encountered when parsing index name: " + idxName + " error:" + e.getMessage());
}
}
}
// Delete identified indexes
IndicesAdminClient indicesAdminClient = elasticClient.admin().indices();
for (String indexToDelete : indexesToDelete) {
DeleteIndexRequest deleteRequest = new DeleteIndexRequest(indexToDelete);
indicesAdminClient.delete(deleteRequest);
}
}
use of org.elasticsearch.client.IndicesAdminClient in project incubator-skywalking by apache.
the class ElasticSearchClient method deleteIndex.
public boolean deleteIndex(String indexName) {
if (!ready) {
throw new ElasticSearchClientNotReadyException();
}
indexName = formatIndexName(indexName);
IndicesAdminClient adminClient = client.admin().indices();
DeleteIndexResponse response = adminClient.prepareDelete(indexName).get();
logger.info("delete {} index finished, isAcknowledged: {}", indexName, response.isAcknowledged());
return response.isAcknowledged();
}
Aggregations