/** * Extract a list of datatype identifiers from the settings. */ private List<String> getDatatypes(final Settings datatypesSettings) { List<String> datatypes = new ArrayList<String>(); for (String key : datatypesSettings.getAsMap().keySet()) { datatypes.add(key.substring(0, key.lastIndexOf('.'))); } return datatypes; }
private Set<String> getMissingIndexes(Set<String> indexes) { try { ImmutableMap<String, IndexMetaData> foundIndices = getIndexMetaData(indexes); indexes.removeAll(foundIndices.keySet()); } catch (IndexMissingException e) { // all indexes are missing } return indexes; }
/** * Retrieves the current indexes and types from elasticsearch * @return a set containing the indexes available in the elasticsearch cluster and their types */ protected Set<Index> getIndexes() { ClusterStateResponse response = unwrapShellNativeClient().client().admin().cluster().prepareState().setFilterBlocks(true) .setFilterRoutingTable(true).setFilterNodes(true).execute().actionGet(); Set<Index> newIndexes = new HashSet<Index>(); for (IndexMetaData indexMetaData : response.getState().metaData().indices().values()) { logger.trace("Processing index {}", indexMetaData.index()); Set<String> typeNames = Sets.filter(indexMetaData.mappings().keySet(), new Predicate<String>() { @Override public boolean apply(String s) { return !MapperService.DEFAULT_MAPPING.equals(s); } }); String[] types = typeNames.toArray(new String[typeNames.size()]); newIndexes.add(new Index(indexMetaData.index(), false, types)); for (String alias : indexMetaData.aliases().keySet()) { newIndexes.add(new Index(alias, true, types)); } } return newIndexes; }
public JsonOutput availableIndices(String... indices) throws Exception { ClusterStateResponse response = this.client.admin().cluster().state(new ClusterStateRequest() .filterBlocks(true).filterNodes(true).filteredIndices(indices) .filterRoutingTable(true)).actionGet(); XContentBuilder builder = JsonXContent.contentBuilder(); builder.startObject(); for (IndexMetaData indexMetaData : response.getState().metaData()) { builder.startObject(indexMetaData.index()); if (indexMetaData.aliases() != null && indexMetaData.aliases().size() > 0) { builder.startArray("aliases"); for (String alias : indexMetaData.aliases().keySet()) { builder.value(alias); } builder.endArray(); } if (indexMetaData.mappings() != null && indexMetaData.mappings().size() > 0) { builder.startArray("types"); for (String alias : indexMetaData.mappings().keySet()) { builder.value(alias); } builder.endArray(); } builder.endObject(); } builder.endObject(); return stringToJson.stringToJson(builder.string()); }