mappings = transportClient.admin() .cluster() .prepareState() .execute() .actionGet()
logger.trace("dropRecreateMapping index[{}] - type[{}]", index, type); client.admin().indices().prepareRefresh(index).get(); ImmutableOpenMap<String, MappingMetaData> mappings = client.admin().cluster().prepareState().get().getState().getMetaData() .index(index).mappings(); logger.trace("mappings contains type {}: {}", type, mappings.containsKey(type));
private void deleteAllIndices() { ImmutableOpenMap<String, IndexMetaData> indices = elasticSearchClient.admin().cluster() .prepareState().get().getState() .getMetaData().getIndices(); indices.forEach(cursor -> { try { elasticSearchClient.admin() .indices() .delete(new DeleteIndexRequest(cursor.value.getIndex().getName())) .get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }); }
break; case CLUSTER: ClusterStateRequestBuilder clusterBld = admin.cluster().prepareState(); ActionFuture<ClusterStateResponse> lafClu = clusterBld.execute(); ClusterStateResponse cluResp = lafClu.actionGet();
private void cleanOrphanIndex() { String[] indices = client.admin().cluster().prepareState().execute().actionGet().getState() .getMetaData().getConcreteAllIndices(); List<String> orphans = Stream.of(indices) .filter(i -> i.startsWith(this.configuration.getAlias())) .filter(i -> 0 == client.admin().indices().getAliases(new GetAliasesRequest().indices(i)) .actionGet().getAliases().size()) .collect(Collectors.toList()); for (String orphan : orphans) { client.admin().indices().delete(new DeleteIndexRequest(orphan)).actionGet(); } }
public boolean assertThatConnectionToElasticsearchIsPossible(String host, int port) throws InterruptedException { final InetSocketAddress address = new InetSocketAddress(host, port); try (TransportClient transportClient = TransportClient.builder().build()) { transportClient.addTransportAddress(new InetSocketTransportAddress(address)); for (int i = 0; i < NUM_RETRIES_TO_CHECK_SERVER_UP; i++) { try { transportClient.admin().cluster().prepareState().execute().actionGet(); return true; } catch (Exception e) { TimeUnit.SECONDS.sleep(7); } } } return false; } }
/** * Prints the current cluster state as debug logging. */ public void logClusterState() { logger.debug("cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get()); }
public boolean assertThatConnectionToElasticsearchIsPossible(String host, int port) throws InterruptedException { final InetSocketAddress address = new InetSocketAddress(host, port); try (TransportClient transportClient = TransportClient.builder().build()) { transportClient.addTransportAddress(new InetSocketTransportAddress(address)); for (int i = 0; i < NUM_RETRIES_TO_CHECK_SERVER_UP; i++) { try { transportClient.admin().cluster().prepareState().execute().actionGet(); return true; } catch (Exception e) { TimeUnit.SECONDS.sleep(7); } } } return false; } }
public boolean assertThatConnectionToElasticsearchIsPossible(String host, int port) throws InterruptedException { final InetSocketAddress address = new InetSocketAddress(host, port); try (TransportClient transportClient = TransportClient.builder().build()) { transportClient.addTransportAddress(new InetSocketTransportAddress(address)); for (int i = 0; i < NUM_RETRIES_TO_CHECK_SERVER_UP; i++) { try { transportClient.admin().cluster().prepareState().execute().actionGet(); return true; } catch (Exception e) { TimeUnit.SECONDS.sleep(7); } } } return false; } }
/** * Returns the name of the current master node in the cluster and executes the request via the node specified * in the viaNode parameter. If viaNode isn't specified a random node will be picked to the send the request to. */ public String getMasterName(@Nullable String viaNode) { try { Client client = viaNode != null ? client(viaNode) : client(); ClusterState state = client.admin().cluster().prepareState().execute().actionGet().getState(); return state.nodes().getMasterNode().getName(); } catch (Exception e) { logger.warn("Can't fetch cluster state", e); throw new RuntimeException("Can't get master node " + e.getMessage(), e); } }
public boolean assertThatConnectionToElasticsearchIsPossible(String host, int port) throws InterruptedException { TransportClient transportClient = new TransportClient(); try { transportClient.addTransportAddress(new InetSocketTransportAddress(host, port)); for (int i = 0; i < NUM_RETRIES_TO_CHECK_SERVER_UP; i++) { try { transportClient.admin().cluster().prepareState().execute().actionGet(); return true; } catch(Exception e) { TimeUnit.SECONDS.sleep(7); } } } finally { transportClient.close(); } return false; }
protected NumShards getNumShards(String index) { MetaData metaData = client().admin().cluster().prepareState().get().getState().metaData(); assertThat(metaData.hasIndex(index), equalTo(true)); int numShards = Integer.valueOf(metaData.index(index).getSettings().get(SETTING_NUMBER_OF_SHARDS)); int numReplicas = Integer.valueOf(metaData.index(index).getSettings().get(SETTING_NUMBER_OF_REPLICAS)); return new NumShards(numShards, numReplicas); }
/** * Mapping定義を取得する. * @param index インデックス名 * @param type タイプ名 * @return Mapping定義 */ public MappingMetaData getMapping(String index, String type) { ClusterState cs = esTransportClient.admin().cluster().prepareState(). setIndices(index).execute().actionGet().getState(); return cs.getMetaData().index(index).mapping(type); }
/** * Return a master node. * * @return */ public synchronized Node masterNode() { final ClusterState state = client().admin().cluster().prepareState() .execute().actionGet().getState(); final String name = state.nodes().getMasterNode().getName(); return getNode(name); }
@Override public String getIndexSettings(ElasticSearchIndexConfig config, String settingName) { String settingValue = null; ClusterStateResponse clusterStateResponse = searchClientService.getClient().admin().cluster().prepareState().setFilterRoutingTable(true) .setFilterNodes(true).setFilterIndices(config.getIndexAliasName()).get(); for (IndexMetaData indexMetaData : clusterStateResponse.getState().getMetaData()) { settingValue = indexMetaData.getSettings().get(settingName); } return settingValue; }
public ClusterHealthStatus waitForRelocation() { final ClusterHealthRequest request = Requests.clusterHealthRequest() .waitForNoRelocatingShards(true); final ClusterHealthResponse actionGet = client().admin().cluster() .health(request).actionGet(); if (actionGet.isTimedOut()) { onFailure("waitForRelocation timed out, cluster state:\n" + "\n" + client().admin().cluster().prepareState().get().getState() + "\n" + client().admin().cluster() .preparePendingClusterTasks().get(), actionGet); } return actionGet.getStatus(); }
@Override public String getIndexSettings(final ElasticSearchIndexConfig config, final String settingName) { String settingValue = null; final ClusterStateResponse clusterStateResponse = searchClientService .getClient().admin().cluster().prepareState() .setRoutingTable(true).setNodes(true) .setIndices(config.getIndexAliasName()).get(); for (final IndexMetaData indexMetaData : clusterStateResponse .getState().getMetaData()) { settingValue = indexMetaData.getSettings().get(settingName); } return settingValue; }
@Override public boolean typeExists(String indexName, String type) { return getAdminClient().cluster().prepareState().execute().actionGet().getState().metaData().index(indexName) .getMappings().containsKey(type); }
private String getLocation() { ClusterStateResponse responsee = runner.node().client().admin().cluster().prepareState().execute().actionGet(); InetSocketTransportAddress address = (InetSocketTransportAddress) responsee.getState().getNodes().getNodes().values().iterator().next().value.getAddress(); return "localhost:" + address.address().getPort(); }
public ImmutableOpenMap<String, IndexMetaData> getIndices() { return client.admin().cluster().prepareState().execute().actionGet().getState().getMetaData().getIndices(); }