@Override public void deleteIndexes(String name, String... otherNames) { GetMappingsResponse mappings = client.nativeClient().admin().indices().prepareGetMappings("_all").get(); Set<String> existingIndices = Sets.newHashSet(mappings.mappings().keysIt()); Stream.concat(Stream.of(name), Arrays.stream(otherNames)) .distinct() .filter(existingIndices::contains) .forEach(this::deleteIndex); }
Iterator<String> indexIterator = mappings.keysIt(); while (indexIterator.hasNext()) {
final Iterator<String> it = aliases.keysIt(); while(it.hasNext()) { final String alias = it.next();
private Iterator<String> loadExistingIndices() { return es.client().nativeClient().admin().indices().prepareGetMappings().get().mappings().keysIt(); }
/** * For interoperability with transport clients older than 6.3, we need to strip customs * from the cluster state that the client might not be able to deserialize * * @param clusterState the cluster state to filter the customs from * @return the adapted cluster state */ public static ClusterState filterCustomsForPre63Clients(ClusterState clusterState) { final ClusterState.Builder builder = ClusterState.builder(clusterState); clusterState.customs().keysIt().forEachRemaining(name -> { if (PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST.contains(name) == false) { builder.removeCustom(name); } }); final MetaData.Builder metaBuilder = MetaData.builder(clusterState.metaData()); clusterState.metaData().customs().keysIt().forEachRemaining(name -> { if (PRE_6_3_METADATA_CUSTOMS_WHITE_LIST.contains(name) == false) { metaBuilder.removeCustom(name); } }); return builder.metaData(metaBuilder).build(); }
allClosedIndices.add(indexMetaData.getIndex().getName()); indexMetaData.getAliases().keysIt().forEachRemaining(duplicateAliasesIndices::add);
@Override public void deleteIndexes(String name, String... otherNames) { GetMappingsResponse mappings = client.nativeClient().admin().indices().prepareGetMappings("_all").get(); Set<String> existingIndices = Sets.newHashSet(mappings.mappings().keysIt()); Stream.concat(Stream.of(name), Arrays.stream(otherNames)) .distinct() .filter(existingIndices::contains) .forEach(this::deleteIndex); }
@Override public String getFirstIndexForAlias(String aliasName) { ImmutableOpenMap<String, List<AliasMetaData>> aliases = client.admin() .indices() .prepareGetAliases(aliasName) .get() .getAliases(); for (Iterator<String> it = aliases.keysIt(); it.hasNext();) { String indexName = it.next(); if (!aliases.get(indexName).isEmpty()) { return indexName; } } return null; }
private void outputMapping(Output output, ImmutableOpenMap<String, MappingMetaData> c) throws IOException { Iterator<String> iter = c.keysIt(); while (iter.hasNext()) { String property = iter.next(); MappingMetaData md = c.get(property); output.line("routing: " + md.routing().toString()); for (Map.Entry<String, Object> e : md.getSourceAsMap().entrySet()) { outputMappingRow(output, e); } } }
@VisibleForTesting protected Set<String> getIndicesFromAliasName() { IndicesAdminClient iac = this.client.admin().indices(); ImmutableOpenMap<String, List<AliasMetaData>> map = iac .getAliases(new GetAliasesRequest(this.configuration.getAlias())).actionGet().getAliases(); final Set<String> allIndices = Sets.newHashSet(); map.keysIt().forEachRemaining(allIndices::add); return allIndices; }
/** * Returns the real index name for a given alias. * @param appid the index name (alias) * @return the real index name (not alias) */ public static String getIndexNameForAlias(String appid) { if (StringUtils.isBlank(appid)) { return null; } GetAliasesResponse get = getClient().admin().indices(). prepareGetAliases(appid).execute().actionGet(); ImmutableOpenMap<String, List<AliasMetaData>> aliases = get.getAliases(); if (aliases.size() > 1) { logger.warn("More than one index for alias {}", appid); } else { return aliases.keysIt().next(); } return null; }
private void copyContextToHeader(final ActionRequest request) { if (SearchGuardPlugin.DLS_SUPPORTED) { final ImmutableOpenMap<Object, Object> map = request.getContext(); final Iterator it = map.keysIt(); while (it.hasNext()) { final Object key = it.next(); if (key instanceof String && key.toString().startsWith("searchguard")) { if (request.hasHeader(key.toString())) { continue; } request.putHeader(key.toString(), SecurityUtil.encryptAndSerializeObject((Serializable) map.get(key), SearchGuardService.getSecretKey())); log.trace("Copy from context to header {}", key); } } } }
@Override public IndexResponse findIndexes(IndexRequest indexRequest) throws ClientException { checkClient(); try { GetSettingsResponse response = esClientProvider.getClient().admin().indices().prepareGetSettings(indexRequest.getIndex()) .get(getQueryTimeout()); List<String> list = new ArrayList<>(); response.getIndexToSettings().keysIt().forEachRemaining(list::add); return new IndexResponse(list.toArray(new String[list.size()])); } catch (IndexNotFoundException e) { return new IndexResponse(new String[0]); } }
@Override public IndexResponse findIndexes(IndexRequest indexRequest) throws ClientException { checkClient(); try { GetSettingsResponse response = esClientProvider.getClient().admin().indices().prepareGetSettings(indexRequest.getIndex()) .get(getQueryTimeout()); List<String> list = new ArrayList<>(); response.getIndexToSettings().keysIt().forEachRemaining(list::add); return new IndexResponse(list.toArray(new String[list.size()])); } catch (IndexNotFoundException e) { return new IndexResponse(new String[0]); } }
final Iterator<String> it = aliases.keysIt(); while(it.hasNext()) { final String alias = it.next();
/** * For interoperability with transport clients older than 6.3, we need to strip customs * from the cluster state that the client might not be able to deserialize * * @param clusterState the cluster state to filter the customs from * @return the adapted cluster state */ public static ClusterState filterCustomsForPre63Clients(ClusterState clusterState) { final ClusterState.Builder builder = ClusterState.builder(clusterState); clusterState.customs().keysIt().forEachRemaining(name -> { if (PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST.contains(name) == false) { builder.removeCustom(name); } }); final MetaData.Builder metaBuilder = MetaData.builder(clusterState.metaData()); clusterState.metaData().customs().keysIt().forEachRemaining(name -> { if (PRE_6_3_METADATA_CUSTOMS_WHITE_LIST.contains(name) == false) { metaBuilder.removeCustom(name); } }); return builder.metaData(metaBuilder).build(); }
/** * For interoperability with transport clients older than 6.3, we need to strip customs * from the cluster state that the client might not be able to deserialize * * @param clusterState the cluster state to filter the customs from * @return the adapted cluster state */ public static ClusterState filterCustomsForPre63Clients(ClusterState clusterState) { final ClusterState.Builder builder = ClusterState.builder(clusterState); clusterState.customs().keysIt().forEachRemaining(name -> { if (PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST.contains(name) == false) { builder.removeCustom(name); } }); final MetaData.Builder metaBuilder = MetaData.builder(clusterState.metaData()); clusterState.metaData().customs().keysIt().forEachRemaining(name -> { if (PRE_6_3_METADATA_CUSTOMS_WHITE_LIST.contains(name) == false) { metaBuilder.removeCustom(name); } }); return builder.metaData(metaBuilder).build(); }
allClosedIndices.add(indexMetaData.getIndex().getName()); indexMetaData.getAliases().keysIt().forEachRemaining(duplicateAliasesIndices::add);
/** * Get the names of templates to delete, if no template is provided the complete list of templates is retrieved */ private Collection<String> getTemplates(Client client) { Collection<String> templatesColl; if (this.templates==null || this.templates.length==0) { // Retrieve all templates ClusterStateRequestBuilder clusterStateRequestBuilder = ClusterStateAction.INSTANCE.newRequestBuilder(client.admin().cluster()) .all().setMetaData(false); ClusterStateResponse clusterStateResponse = clusterStateRequestBuilder.execute().actionGet(); templatesColl = Lists.newArrayList(clusterStateResponse.getState().getMetaData().getTemplates().keysIt()); } else { // Use provided templates templatesColl = Arrays.asList(templates); } return templatesColl; } @Override
/** * Get the names of templates to delete, if no template is provided the complete list of templates is retrieved */ private Collection<String> getTemplates(Client client) { Collection<String> templatesColl; if (this.templates==null || this.templates.length==0) { // Retrieve all templates ClusterStateRequestBuilder clusterStateRequestBuilder = ClusterStateAction.INSTANCE.newRequestBuilder(client.admin().cluster()) .all().setMetaData(false); ClusterStateResponse clusterStateResponse = clusterStateRequestBuilder.execute().actionGet(); templatesColl = Lists.newArrayList(clusterStateResponse.getState().getMetaData().getTemplates().keysIt()); } else { // Use provided templates templatesColl = Arrays.asList(templates); } return templatesColl; } @Override