use of org.elasticsearch.client.IndicesAdminClient in project incubator-skywalking by apache.
the class ElasticSearchClient method createIndex.
public boolean createIndex(String indexName, String indexType, Settings settings, XContentBuilder mappingBuilder) {
if (!ready) {
throw new ElasticSearchClientNotReadyException();
}
IndicesAdminClient adminClient = client.admin().indices();
indexName = formatIndexName(indexName);
CreateIndexResponse response = adminClient.prepareCreate(indexName).setSettings(settings).addMapping(indexType, mappingBuilder).get();
logger.info("create {} index with type of {} finished, isAcknowledged: {}", indexName, indexType, response.isAcknowledged());
return response.isShardsAcked();
}
use of org.elasticsearch.client.IndicesAdminClient in project components by Talend.
the class ElasticsearchTestUtils method deleteIndex.
/**
* Deletes an index and block until deletion is complete.
*
* @param index The index to delete
* @param client The client which points to the Elasticsearch instance
* @throws InterruptedException if blocking thread is interrupted or index existence check failed
* @throws java.util.concurrent.ExecutionException if index existence check failed
* @throws IOException if deletion failed
*/
static void deleteIndex(String index, Client client) throws InterruptedException, java.util.concurrent.ExecutionException, IOException {
IndicesAdminClient indices = client.admin().indices();
IndicesExistsResponse indicesExistsResponse = indices.exists(new IndicesExistsRequest(index)).get();
if (indicesExistsResponse.isExists()) {
indices.prepareClose(index).get();
// delete index is an asynchronous request, neither refresh or upgrade
// delete all docs before starting tests. WaitForYellow() and delete directory are too slow,
// so block thread until it is done (make it synchronous!!!)
AtomicBoolean indexDeleted = new AtomicBoolean(false);
AtomicBoolean waitForIndexDeletion = new AtomicBoolean(true);
indices.delete(Requests.deleteIndexRequest(index), new DeleteActionListener(indexDeleted, waitForIndexDeletion));
while (waitForIndexDeletion.get()) {
Thread.sleep(100);
}
if (!indexDeleted.get()) {
throw new IOException("Failed to delete index " + index);
}
}
}
use of org.elasticsearch.client.IndicesAdminClient in project play2-elasticsearch by cleverage.
the class IndexService method existsIndex.
/**
* Test if an indice Exists
* @return true if exists
*/
public static boolean existsIndex(String indexName) {
Client client = IndexClient.client;
AdminClient admin = client.admin();
IndicesAdminClient indices = admin.indices();
IndicesExistsRequestBuilder indicesExistsRequestBuilder = indices.prepareExists(indexName);
IndicesExistsResponse response = indicesExistsRequestBuilder.execute().actionGet();
return response.isExists();
}
use of org.elasticsearch.client.IndicesAdminClient in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method deleteIndexes.
private void deleteIndexes(final List<String> names) throws CalFacadeException {
try {
final IndicesAdminClient idx = getAdminIdx();
final DeleteIndexRequestBuilder dirb = getAdminIdx().prepareDelete(names.toArray(new String[names.size()]));
final ActionFuture<DeleteIndexResponse> dr = idx.delete(dirb.request());
/*DeleteIndexResponse dir = */
dr.actionGet();
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.elasticsearch.client.IndicesAdminClient in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method getIndexInfo.
@Override
public Set<IndexInfo> getIndexInfo() throws CalFacadeException {
final Set<IndexInfo> res = new TreeSet<>();
try {
final IndicesAdminClient idx = getAdminIdx();
final IndicesStatusRequestBuilder isrb = idx.prepareStatus(Strings.EMPTY_ARRAY);
final ActionFuture<IndicesStatusResponse> sr = idx.status(isrb.request());
final IndicesStatusResponse sresp = sr.actionGet();
for (final String inm : sresp.getIndices().keySet()) {
final IndexInfo ii = new IndexInfo(inm);
res.add(ii);
final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().routingTable(true).nodes(true).indices(inm);
final Iterator<String> it = getAdminCluster().state(clusterStateRequest).actionGet().getState().getMetaData().aliases().keysIt();
while (it.hasNext()) {
ii.addAlias(it.next());
}
}
return res;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations