String[] concreteIndexNames(Context context, String... indexExpressions) { Index[] indexes = concreteIndices(context, indexExpressions); String[] names = new String[indexes.length]; for (int i = 0; i < indexes.length; i++) { names[i] = indexes[i].getName(); } return names; }
@Override public String[] provide(String[] original, Object request, boolean supportsReplace) { if(supportsReplace) { if(retainMode && original != null && original.length > 0) { //TODO datemath? List<String> originalAsList = Arrays.asList(original); if(originalAsList.contains("*") || originalAsList.contains("_all")) { return replacements; } original = resolver.concreteIndexNames(clusterService.state(), IndicesOptions.lenientExpandOpen(), original); final String[] retained = WildcardMatcher.getMatchAny(original, replacements).toArray(new String[0]); return retained; } return replacements; } else { return NOOP; } } }, false);
IndicesRequest.Replaceable searchRequest = request; final Map<String, OriginalIndices> remoteClusterIndices = SearchGuardPlugin.GuiceHolder.getRemoteClusterService().groupIndices( searchRequest.indicesOptions(), searchRequest.indices(), idx -> resolver.hasIndexOrAlias(idx, clusterService.state()));
final String requestedPattern = resolver.resolveDateMathExpression(requestedPatterns[i]); final List<String> _aliases = WildcardMatcher.getMatchAny(requestedPattern, aliases); matchingAliases.addAll(_aliases); _indices = new ArrayList<>(Arrays.asList(resolver.concreteIndexNames(state, IndicesOptions.fromOptions(false, true, true, false), requestedPatterns))); if (log.isDebugEnabled()) { log.debug("Resolved pattern {} to {}", requestedPatterns, _indices); _indices.add(resolver.resolveDateMathExpression(requestedPattern));
public AliasFilter buildAliasFilter(ClusterState state, String index, String... expressions) { /* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch * of dependencies we pass in a function that can perform the parsing. */ CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> { try (XContentParser parser = XContentFactory.xContent(bytes) .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes)) { return parseInnerQueryBuilder(parser); } }; String[] aliases = indexNameExpressionResolver.filteringAliases(state, index, expressions); IndexMetaData indexMetaData = state.metaData().index(index); return new AliasFilter(ShardSearchRequest.parseAliasFilter(filterParser, indexMetaData, aliases), aliases); }
public static final boolean isAll(final String... requestedPatterns) { final List<String> patterns = requestedPatterns==null?null:Arrays.asList(requestedPatterns); if(IndexNameExpressionResolver.isAllIndices(patterns)) { return true; } if(patterns.contains("*")) { return true; } if(patterns.contains("_all")) { return true; } if(new HashSet<String>(patterns).equals(NULL_SET)) { return true; } return false; }
@Override protected GroupShardsIterator shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) { final String routing; if (request.allShards()) { routing = null; } else { // Random routing to limit request to a single shard routing = Integer.toString(Randomness.get().nextInt(1000)); } Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, routing, request.indices()); return clusterService.operationRouting().searchShards(clusterState, concreteIndices, routingMap, "_local"); }
static String generateRolloverIndexName(String sourceIndexName, IndexNameExpressionResolver indexNameExpressionResolver) { String resolvedName = indexNameExpressionResolver.resolveDateMathExpression(sourceIndexName); final boolean isDateMath = sourceIndexName.equals(resolvedName) == false; if (INDEX_NAME_PATTERN.matcher(resolvedName).matches()) { int numberIndex = sourceIndexName.lastIndexOf("-"); assert numberIndex != -1 : "no separator '-' found"; int counter = Integer.parseInt(sourceIndexName.substring(numberIndex + 1, isDateMath ? sourceIndexName.length()-1 : sourceIndexName.length())); String newName = sourceIndexName.substring(0, numberIndex) + "-" + String.format(Locale.ROOT, "%06d", ++counter) + (isDateMath ? ">" : ""); return newName; } else { throw new IllegalArgumentException("index name [" + sourceIndexName + "] does not match pattern '^.*-\\d+$'"); } }
private String concreteIndex(final ClusterState state, final ReplicationRequest request) { return resolveIndex() ? indexNameExpressionResolver.concreteSingleIndex(state, request).getName() : request.index(); }
final ActionListener<ClusterSearchShardsResponse> listener) { ClusterState clusterState = clusterService.state(); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(state, request.routing(), request.indices()); Map<String, AliasFilter> indicesAndFilters = new HashMap<>(); for (String index : concreteIndices) { final AliasFilter aliasFilter = indicesService.buildAliasFilter(clusterState, index, request.indices()); final String[] aliases = indexNameExpressionResolver.indexAliases(clusterState, index, aliasMetadata -> true, true, request.indices()); indicesAndFilters.put(index, new AliasFilter(aliasFilter.getQueryBuilder(), aliases));
final ClusterState clusterState = clusterService.state(); final Map<String, OriginalIndices> remoteClusterIndices = remoteClusterService.groupIndices(request.indicesOptions(), request.indices(), idx -> indexNameExpressionResolver.hasIndexOrAlias(idx, clusterState)); final OriginalIndices localIndices = remoteClusterIndices.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY); final String[] concreteIndices; concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, localIndices);
final IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(settings); irr = new IndexResolverReplacer(resolver, clusterService, cih); auditLog = ReflectionHelper.instantiateAuditLog(settings, configPath, localClient, threadPool, resolver, clusterService);
if (isAllIndices(resolvedExpressions)) { return resolveSearchRoutingAllIndices(state.metaData(), routing);
/** * Identifies whether the array containing index names given as argument refers to all indices * The empty or null array identifies all indices * * @param aliasesOrIndices the array containing index names * @return true if the provided array maps to all indices, false otherwise */ public static boolean isAllIndices(List<String> aliasesOrIndices) { return aliasesOrIndices == null || aliasesOrIndices.isEmpty() || isExplicitAllPattern(aliasesOrIndices); }
@Override protected ShardDfsOnlyRequest newShardRequest(int numShards, ShardRouting shard, DfsOnlyRequest request) { String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterService.state(), shard.index(), request.indices()); return new ShardDfsOnlyRequest(shard, numShards, filteringAliases, request.nowInMillis, request); }
if (IndexNameExpressionResolver.isAllIndices(Arrays.asList(selectedIndices))) { return availableIndices;
Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, searchRequest.routing(), searchRequest.indices()); routingMap = routingMap == null ? Collections.emptyMap() : Collections.unmodifiableMap(routingMap);
@Override protected void masterOperation(final ResizeRequest resizeRequest, final ClusterState state, final ActionListener<ResizeResponse> listener) { // there is no need to fetch docs stats for split but we keep it simple and do it anyway for simplicity of the code final String sourceIndex = indexNameExpressionResolver.resolveDateMathExpression(resizeRequest.getSourceIndex()); final String targetIndex = indexNameExpressionResolver.resolveDateMathExpression(resizeRequest.getTargetIndexRequest().index()); client.admin().indices().prepareStats(sourceIndex).clear().setDocs(true).execute(new ActionListener<IndicesStatsResponse>() { @Override public void onResponse(IndicesStatsResponse indicesStatsResponse) { CreateIndexClusterStateUpdateRequest updateRequest = prepareCreateIndexRequest(resizeRequest, state, (i) -> { IndexShardStats shard = indicesStatsResponse.getIndex(sourceIndex).getIndexShards().get(i); return shard == null ? null : shard.getPrimary().getDocs(); }, sourceIndex, targetIndex); createIndexService.createIndex( updateRequest, ActionListener.wrap(response -> listener.onResponse(new ResizeResponse(response.isAcknowledged(), response.isShardsAcknowledged(), updateRequest.index())), listener::onFailure ) ); } @Override public void onFailure(Exception e) { listener.onFailure(e); } }); }
concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item).getName();
public ClusterModule(Settings settings, ClusterService clusterService, List<ClusterPlugin> clusterPlugins, ClusterInfoService clusterInfoService) { this.deciderList = createAllocationDeciders(settings, clusterService.getClusterSettings(), clusterPlugins); this.allocationDeciders = new AllocationDeciders(deciderList); this.shardsAllocator = createShardsAllocator(settings, clusterService.getClusterSettings(), clusterPlugins); this.clusterService = clusterService; this.indexNameExpressionResolver = new IndexNameExpressionResolver(settings); this.allocationService = new AllocationService(allocationDeciders, shardsAllocator, clusterInfoService); }