Search in sources :

Example 16 with IndicesAdminClient

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();
    }
}
Also used : IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 17 with IndicesAdminClient

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 -> {
        });
    }
}
Also used : IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient)

Example 18 with IndicesAdminClient

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();
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) IOException(java.io.IOException) PutIndexTemplateRequestBuilder(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder) URL(java.net.URL)

Example 19 with IndicesAdminClient

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);
    }
}
Also used : ArrayList(java.util.ArrayList) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 20 with IndicesAdminClient

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();
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient)

Aggregations

IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)27 IndicesExistsResponse (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse)6 Test (org.junit.Test)6 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 IndicesAliasesResponse (org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)3 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)3 DeleteIndexTemplateResponse (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse)3 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)3 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)2 GetAliasesResponse (org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse)2 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)2 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)2 GetIndexResponse (org.elasticsearch.action.admin.indices.get.GetIndexResponse)2 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)2