use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder in project pentaho-kettle by pentaho.
the class ElasticSearchBulkDialog method test.
private void test(TestType testType) {
// Save off the thread's context class loader to restore after the test
ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader();
// Now ensure that the thread's context class loader is the plugin's classloader
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
Client client = null;
Node node = null;
try {
ElasticSearchBulkMeta tempMeta = new ElasticSearchBulkMeta();
toModel(tempMeta);
Settings.Builder settingsBuilder = Settings.settingsBuilder();
// keep default classloader
settingsBuilder.put(Settings.Builder.EMPTY_SETTINGS);
settingsBuilder.put(tempMeta.getSettingsMap());
TransportClient.Builder tClientBuilder = TransportClient.builder().settings(settingsBuilder);
if (!tempMeta.getServers().isEmpty()) {
node = null;
TransportClient tClient = tClientBuilder.build();
for (ElasticSearchBulkMeta.Server s : tempMeta.getServers()) {
tClient.addTransportAddress(s.getAddr());
}
client = tClient;
} else {
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder();
nodeBuilder.settings(settingsBuilder);
node = nodeBuilder.client(true).node();
client = node.client();
node.start();
}
AdminClient admin = client.admin();
switch(testType) {
case INDEX:
if (StringUtils.isBlank(tempMeta.getIndex())) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulk.Error.NoIndex"));
break;
}
// First check to see if the index exists
IndicesExistsRequestBuilder indicesExistBld = admin.indices().prepareExists(tempMeta.getIndex());
IndicesExistsResponse indicesExistResponse = indicesExistBld.execute().get();
if (!indicesExistResponse.isExists()) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoIndex"));
return;
}
RecoveryRequestBuilder indicesBld = admin.indices().prepareRecoveries(tempMeta.getIndex());
ListenableActionFuture<RecoveryResponse> lafInd = indicesBld.execute();
String shards = "" + lafInd.get().getSuccessfulShards() + "/" + lafInd.get().getTotalShards();
showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestIndex.TestOK", shards));
break;
case CLUSTER:
ClusterStateRequestBuilder clusterBld = admin.cluster().prepareState();
ListenableActionFuture<ClusterStateResponse> lafClu = clusterBld.execute();
ClusterStateResponse cluResp = lafClu.actionGet();
String name = cluResp.getClusterName().value();
ClusterState cluState = cluResp.getState();
int numNodes = cluState.getNodes().size();
showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestCluster.TestOK", name, numNodes));
break;
default:
break;
}
} catch (NoNodeAvailableException e) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoNodesFound"));
} catch (MasterNotDiscoveredException e) {
showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoNodesFound"));
} catch (Exception e) {
showError(e.getLocalizedMessage());
} finally {
if (client != null) {
client.close();
}
if (node != null) {
node.close();
}
}
// Restore the original classloader
Thread.currentThread().setContextClassLoader(originalClassloader);
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder in project molgenis by molgenis.
the class ClientFacade method indexesExist.
private boolean indexesExist(List<Index> indexes) {
if (LOG.isTraceEnabled()) {
LOG.trace("Determining index(es) '{}' existence ...", toString(indexes));
}
String[] indexNames = toIndexNames(indexes);
IndicesExistsRequestBuilder indicesExistsRequest = client.admin().indices().prepareExists(indexNames);
IndicesExistsResponse indicesExistsResponse;
try {
indicesExistsResponse = indicesExistsRequest.get();
} catch (ElasticsearchException e) {
LOG.error("", e);
throw new IndexException(format("Error determining index(es) '%s' existence.", toString(indexes)));
}
boolean exists = indicesExistsResponse.isExists();
if (LOG.isDebugEnabled()) {
LOG.debug("Determined index(es) '{}' existence: {}.", toString(indexes), exists);
}
return exists;
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder in project elasticsearch by elastic.
the class IndicesExistsIT method testIndicesExists.
// Indices exists never throws IndexMissingException, the indices options control its behaviour (return true or false)
public void testIndicesExists() throws Exception {
assertFalse(client().admin().indices().prepareExists("foo").get().isExists());
assertFalse(client().admin().indices().prepareExists("foo*").get().isExists());
assertFalse(client().admin().indices().prepareExists("_all").get().isExists());
createIndex("foo", "foobar", "bar", "barbaz");
IndicesExistsRequestBuilder indicesExistsRequestBuilder = client().admin().indices().prepareExists("foo*").setExpandWildcardsOpen(false);
IndicesExistsRequest request = indicesExistsRequestBuilder.request();
//check that ignore unavailable and allow no indices are set to false. That is their only valid value as it can't be overridden
assertFalse(request.indicesOptions().ignoreUnavailable());
assertFalse(request.indicesOptions().allowNoIndices());
assertThat(indicesExistsRequestBuilder.get().isExists(), equalTo(false));
assertAcked(client().admin().indices().prepareClose("foobar").get());
assertThat(client().admin().indices().prepareExists("foo*").get().isExists(), equalTo(true));
assertThat(client().admin().indices().prepareExists("foo*").setExpandWildcardsOpen(false).setExpandWildcardsClosed(false).get().isExists(), equalTo(false));
assertThat(client().admin().indices().prepareExists("foobar").get().isExists(), equalTo(true));
assertThat(client().admin().indices().prepareExists("foob*").setExpandWildcardsClosed(false).get().isExists(), equalTo(false));
assertThat(client().admin().indices().prepareExists("bar*").get().isExists(), equalTo(true));
assertThat(client().admin().indices().prepareExists("bar").get().isExists(), equalTo(true));
assertThat(client().admin().indices().prepareExists("_all").get().isExists(), equalTo(true));
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder 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();
}
Aggregations