org.elasticsearch.common.regex.Regex Java Examples

The following examples show how to use org.elasticsearch.common.regex.Regex. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ESIntegTestCase.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that all shards are allocated on nodes matching the given node pattern.
 */
public Set<String> assertAllShardsOnNodes(String index, String... pattern) {
    Set<String> nodes = new HashSet<>();
    ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                if (shardRouting.currentNodeId() != null && index.equals(shardRouting.getIndexName())) {
                    String name = clusterState.nodes().get(shardRouting.currentNodeId()).getName();
                    nodes.add(name);
                    assertThat("Allocated on new node: " + name, Regex.simpleMatch(pattern, name), is(true));
                }
            }
        }
    }
    return nodes;
}
 
Example #2
Source File: IndexNameExpressionResolver.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Identifies whether the first argument (an array containing index names) is a pattern that matches all indices
 *
 * @param indicesOrAliases the array containing index names
 * @param concreteIndices  array containing the concrete indices that the first argument refers to
 * @return true if the first argument is a pattern that maps to all available indices, false otherwise
 */
boolean isPatternMatchingAllIndices(MetaData metaData, String[] indicesOrAliases, String[] concreteIndices) {
    // if we end up matching on all indices, check, if its a wildcard parameter, or a "-something" structure
    if (concreteIndices.length == metaData.getConcreteAllIndices().length && indicesOrAliases.length > 0) {

        //we might have something like /-test1,+test1 that would identify all indices
        //or something like /-test1 with test1 index missing and IndicesOptions.lenient()
        if (indicesOrAliases[0].charAt(0) == '-') {
            return true;
        }

        //otherwise we check if there's any simple regex
        for (String indexOrAlias : indicesOrAliases) {
            if (Regex.isSimpleMatchPattern(indexOrAlias)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #3
Source File: IndexNameExpressionResolver.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Identifies whether the first argument (an array containing index names) is a pattern that matches all indices
 *
 * @param indicesOrAliases the array containing index names
 * @param concreteIndices  array containing the concrete indices that the first argument refers to
 * @return true if the first argument is a pattern that maps to all available indices, false otherwise
 */
boolean isPatternMatchingAllIndices(MetaData metaData, String[] indicesOrAliases, String[] concreteIndices) {
    // if we end up matching on all indices, check, if its a wildcard parameter, or a "-something" structure
    if (concreteIndices.length == metaData.concreteAllIndices().length && indicesOrAliases.length > 0) {

        //we might have something like /-test1,+test1 that would identify all indices
        //or something like /-test1 with test1 index missing and IndicesOptions.lenient()
        if (indicesOrAliases[0].charAt(0) == '-') {
            return true;
        }

        //otherwise we check if there's any simple regex
        for (String indexOrAlias : indicesOrAliases) {
            if (Regex.isSimpleMatchPattern(indexOrAlias)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #4
Source File: IndexNameExpressionResolver.java    From crate with Apache License 2.0 6 votes vote down vote up
public static Map<String, AliasOrIndex> matches(Context context, MetaData metaData, String expression) {
    if (Regex.isMatchAllPattern(expression)) {
        // Can only happen if the expressions was initially: '-*'
        if (context.getOptions().ignoreAliases()) {
            return metaData.getAliasAndIndexLookup().entrySet().stream()
                    .filter(e -> e.getValue().isAlias() == false)
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        } else {
            return metaData.getAliasAndIndexLookup();
        }
    } else if (expression.indexOf("*") == expression.length() - 1) {
        return suffixWildcard(context, metaData, expression);
    } else {
        return otherWildcard(context, metaData, expression);
    }
}
 
Example #5
Source File: SettingsFilter.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static Settings filterSettings(String patterns, Settings settings) {
    String[] patternArray = Strings.delimitedListToStringArray(patterns, ",");
    Settings.Builder builder = Settings.settingsBuilder().put(settings);
    List<String> simpleMatchPatternList = new ArrayList<>();
    for (String pattern : patternArray) {
        if (Regex.isSimpleMatchPattern(pattern)) {
            simpleMatchPatternList.add(pattern);
        } else {
            builder.remove(pattern);
        }
    }
    if (!simpleMatchPatternList.isEmpty()) {
        String[] simpleMatchPatterns = simpleMatchPatternList.toArray(new String[simpleMatchPatternList.size()]);
        Iterator<Entry<String, String>> iterator = builder.internalMap().entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> current = iterator.next();
            if (Regex.simpleMatch(simpleMatchPatterns, current.getKey())) {
                iterator.remove();
            }
        }
    }
    return builder.build();
}
 
Example #6
Source File: TransportCreatePartitionsAction.java    From crate with Apache License 2.0 6 votes vote down vote up
private List<IndexTemplateMetaData> findTemplates(CreatePartitionsRequest request, ClusterState state) {
    List<IndexTemplateMetaData> templates = new ArrayList<>();
    String firstIndex = request.indices().iterator().next();


    // note: only use the first index name to see if template matches.
    // this means
    for (ObjectCursor<IndexTemplateMetaData> cursor : state.metaData().templates().values()) {
        IndexTemplateMetaData template = cursor.value;
        for (String pattern : template.getPatterns()) {
            if (Regex.simpleMatch(pattern, firstIndex)) {
                templates.add(template);
                break;
            }
        }
    }
    CollectionUtil.timSort(templates, (o1, o2) -> o2.order() - o1.order());
    return templates;
}
 
Example #7
Source File: TransportGetIndexTemplatesAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(GetIndexTemplatesRequest request, ClusterState state, ActionListener<GetIndexTemplatesResponse> listener) {
    List<IndexTemplateMetaData> results;

    // If we did not ask for a specific name, then we return all templates
    if (request.names().length == 0) {
        results = Arrays.asList(state.metaData().templates().values().toArray(IndexTemplateMetaData.class));
    } else {
        results = new ArrayList<>();
    }

    for (String name : request.names()) {
        if (Regex.isSimpleMatchPattern(name)) {
            for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : state.metaData().templates()) {
                if (Regex.simpleMatch(name, entry.key)) {
                    results.add(entry.value);
                }
            }
        } else if (state.metaData().templates().containsKey(name)) {
            results.add(state.metaData().templates().get(name));
        }
    }

    listener.onResponse(new GetIndexTemplatesResponse(results));
}
 
Example #8
Source File: TransportGetIndexTemplatesAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(GetIndexTemplatesRequest request, ClusterState state, ActionListener<GetIndexTemplatesResponse> listener) {
    List<IndexTemplateMetaData> results;

    // If we did not ask for a specific name, then we return all templates
    if (request.names().length == 0) {
        results = Arrays.asList(state.metaData().templates().values().toArray(IndexTemplateMetaData.class));
    } else {
        results = new ArrayList<>();
    }

    for (String name : request.names()) {
        if (Regex.isSimpleMatchPattern(name)) {
            for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : state.metaData().templates()) {
                if (Regex.simpleMatch(name, entry.key)) {
                    results.add(entry.value);
                }
            }
        } else if (state.metaData().templates().containsKey(name)) {
            results.add(state.metaData().templates().get(name));
        }
    }

    listener.onResponse(new GetIndexTemplatesResponse(results));
}
 
Example #9
Source File: GeoExtensionProcessor.java    From elasticsearch-plugin-geoshape with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private List<String> getGeoShapeFieldsFromDoc(IngestDocument ingestDocument) {
    List<String> fields = new ArrayList<>();

    Map<String, Object> baseMap;
    if (path != null) {
        baseMap = ingestDocument.getFieldValue(this.path, Map.class);
    } else {
        baseMap = ingestDocument.getSourceAndMetadata();
    }

    for (String fieldName : baseMap.keySet()) {
        if (Regex.simpleMatch(field, fieldName)) {
            if (path != null) {
                fieldName = path + "." + fieldName;
            }
            fields.add(fieldName);
        }
    }

    return fields;
}
 
Example #10
Source File: PatternAnalyzerProvider.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public PatternAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, Environment env, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);

    Version esVersion = Version.indexCreated(indexSettingsService.getSettings());
    final CharArraySet defaultStopwords;
    if (esVersion.onOrAfter(Version.V_1_0_0_RC1)) {
        defaultStopwords = CharArraySet.EMPTY_SET;
    } else {
        defaultStopwords = StopAnalyzer.ENGLISH_STOP_WORDS_SET;
    }
    boolean lowercase = settings.getAsBoolean("lowercase", true);
    CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);

    String sPattern = settings.get("pattern", "\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/);
    if (sPattern == null) {
        throw new IllegalArgumentException("Analyzer [" + name + "] of type pattern must have a `pattern` set");
    }
    Pattern pattern = Regex.compile(sPattern, settings.get("flags"));

    analyzer = new PatternAnalyzer(pattern, lowercase, stopWords);
}
 
Example #11
Source File: CommonAnalysisPlugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public List<PreConfiguredTokenizer> getPreConfiguredTokenizers() {
    List<PreConfiguredTokenizer> tokenizers = new ArrayList<>();
    tokenizers.add(PreConfiguredTokenizer.singleton("keyword", KeywordTokenizer::new, null));
    tokenizers.add(PreConfiguredTokenizer.singleton("classic", ClassicTokenizer::new, null));
    tokenizers.add(PreConfiguredTokenizer.singleton("uax_url_email", UAX29URLEmailTokenizer::new, null));
    tokenizers.add(PreConfiguredTokenizer.singleton("path_hierarchy", PathHierarchyTokenizer::new, null));
    tokenizers.add(PreConfiguredTokenizer.singleton("letter", LetterTokenizer::new, null));
    tokenizers.add(PreConfiguredTokenizer.singleton("whitespace", WhitespaceTokenizer::new, null));
    tokenizers.add(PreConfiguredTokenizer.singleton("ngram", NGramTokenizer::new, null));
    tokenizers.add(PreConfiguredTokenizer.singleton("edge_ngram",
        () -> new EdgeNGramTokenizer(EdgeNGramTokenizer.DEFAULT_MIN_GRAM_SIZE, EdgeNGramTokenizer.DEFAULT_MAX_GRAM_SIZE), null));
    tokenizers.add(PreConfiguredTokenizer.singleton("pattern", () -> new PatternTokenizer(Regex.compile("\\W+", null), -1), null));
    tokenizers.add(PreConfiguredTokenizer.singleton("thai", ThaiTokenizer::new, null));
    tokenizers.add(PreConfiguredTokenizer.singleton("lowercase", XLowerCaseTokenizer::new, () -> new TokenFilterFactory() {
        @Override
        public String name() {
            return "lowercase";
        }

        @Override
        public TokenStream create(TokenStream tokenStream) {
            return new LowerCaseFilter(tokenStream);
        }
    }));

    // Temporary shim for aliases. TODO deprecate after they are moved
    tokenizers.add(PreConfiguredTokenizer.singleton("PathHierarchy", PathHierarchyTokenizer::new, null));

    return tokenizers;
}
 
Example #12
Source File: MultiMatchQueryParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void extractFieldAndBoost(QueryParseContext parseContext, XContentParser parser, Map<String, Float> fieldNameWithBoosts) throws IOException {
    String fField = null;
    Float fBoost = null;
    char[] fieldText = parser.textCharacters();
    int end = parser.textOffset() + parser.textLength();
    for (int i = parser.textOffset(); i < end; i++) {
        if (fieldText[i] == '^') {
            int relativeLocation = i - parser.textOffset();
            fField = new String(fieldText, parser.textOffset(), relativeLocation);
            fBoost = Float.parseFloat(new String(fieldText, i + 1, parser.textLength() - relativeLocation - 1));
            break;
        }
    }
    if (fField == null) {
        fField = parser.text();
    }

    if (Regex.isSimpleMatchPattern(fField)) {
        for (String field : parseContext.mapperService().simpleMatchToIndexNames(fField)) {
            fieldNameWithBoosts.put(field, fBoost);
        }
    } else {
        fieldNameWithBoosts.put(fField, fBoost);
    }
}
 
Example #13
Source File: BaseTasksRequest.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public boolean match(Task task) {
    if (getActions() != null && getActions().length > 0 && Regex.simpleMatch(getActions(), task.getAction()) == false) {
        return false;
    }
    if (getTaskId().isSet()) {
        if(getTaskId().getId() != task.getId()) {
            return false;
        }
    }
    if (parentTaskId.isSet()) {
        if (parentTaskId.equals(task.getParentTaskId()) == false) {
            return false;
        }
    }
    return true;
}
 
Example #14
Source File: QueryParserHelper.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve all the field names and patterns present in the provided map with the
 * {@link QueryShardContext} and returns a new map containing all the expanded fields with their original boost.
 * @param context The context of the query.
 * @param fieldsAndWeights The map of fields and weights to expand.
 * @param fieldSuffix The suffix name to add to the expanded field names if a mapping exists for that name.
 *                    The original name of the field is kept if adding the suffix to the field name does not point to a valid field
 *                    in the mapping.
 */
public static Map<String, Float> resolveMappingFields(QueryShardContext context,
                                                      Map<String, Float> fieldsAndWeights,
                                                      String fieldSuffix) {
    Map<String, Float> resolvedFields = new HashMap<>();
    for (Map.Entry<String, Float> fieldEntry : fieldsAndWeights.entrySet()) {
        boolean allField = Regex.isMatchAllPattern(fieldEntry.getKey());
        boolean multiField = Regex.isSimpleMatchPattern(fieldEntry.getKey());
        float weight = fieldEntry.getValue() == null ? 1.0f : fieldEntry.getValue();
        Map<String, Float> fieldMap = resolveMappingField(context, fieldEntry.getKey(), weight,
            !multiField, !allField, fieldSuffix);
        resolvedFields.putAll(fieldMap);
    }
    return resolvedFields;
}
 
Example #15
Source File: MapperService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all the fields that match the given pattern. If the pattern is prefixed with a type
 * then the fields will be returned with a type prefix.
 */
public Collection<String> simpleMatchToFullName(String pattern) {
    if (Regex.isSimpleMatchPattern(pattern) == false) {
        // no wildcards
        return Collections.singletonList(pattern);
    }
    return fieldTypes.simpleMatchToFullName(pattern);
}
 
Example #16
Source File: DiscoveryNodeFilters.java    From crate with Apache License 2.0 5 votes vote down vote up
private boolean matchByIP(String[] values, @Nullable String hostIp, @Nullable String publishIp) {
    for (String value : values) {
        boolean matchIp = Regex.simpleMatch(value, hostIp) || Regex.simpleMatch(value, publishIp);
        if (matchIp) {
            return matchIp;
        }
    }
    return false;
}
 
Example #17
Source File: FieldTypeLookup.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of the full names of a simple match regex like pattern against full name and index name.
 */
public Collection<String> simpleMatchToFullName(String pattern) {
    Set<String> fields = new HashSet<>();
    for (MappedFieldType fieldType : this) {
        if (Regex.simpleMatch(pattern, fieldType.name())) {
            fields.add(fieldType.name());
        }
    }
    for (String aliasName : aliasToConcreteName.keySet()) {
        if (Regex.simpleMatch(pattern, aliasName)) {
            fields.add(aliasName);
        }
    }
    return fields;
}
 
Example #18
Source File: TransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
private boolean shouldTraceAction(String action) {
    if (tracerLogInclude.length > 0) {
        if (Regex.simpleMatch(tracerLogInclude, action) == false) {
            return false;
        }
    }
    if (tracerLogExclude.length > 0) {
        return !Regex.simpleMatch(tracerLogExclude, action);
    }
    return true;
}
 
Example #19
Source File: MetaDataIndexTemplateService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Finds index templates whose index pattern matched with the given index name.
 * The result is sorted by {@link IndexTemplateMetaData#order} descending.
 */
public static List<IndexTemplateMetaData> findTemplates(MetaData metaData, String indexName) {
    final List<IndexTemplateMetaData> matchedTemplates = new ArrayList<>();
    for (ObjectCursor<IndexTemplateMetaData> cursor : metaData.templates().values()) {
        final IndexTemplateMetaData template = cursor.value;
        final boolean matched = template.patterns().stream().anyMatch(pattern -> Regex.simpleMatch(pattern, indexName));
        if (matched) {
            matchedTemplates.add(template);
        }
    }
    CollectionUtil.timSort(matchedTemplates, Comparator.comparingInt(IndexTemplateMetaData::order).reversed());
    return matchedTemplates;
}
 
Example #20
Source File: IndexNameExpressionResolver.java    From crate with Apache License 2.0 5 votes vote down vote up
private static Map<String, AliasOrIndex> otherWildcard(Context context, MetaData metaData, String expression) {
    final String pattern = expression;
    return metaData.getAliasAndIndexLookup()
        .entrySet()
        .stream()
        .filter(e -> context.getOptions().ignoreAliases() == false || e.getValue().isAlias() == false)
        .filter(e -> Regex.simpleMatch(pattern, e.getKey()))
        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
 
Example #21
Source File: PatternReplaceTokenFilterFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
public PatternReplaceTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
    super(indexSettings, name, settings);

    String sPattern = settings.get("pattern", null);
    if (sPattern == null) {
        throw new IllegalArgumentException("pattern is missing for [" + name + "] token filter of type 'pattern_replace'");
    }
    this.pattern = Regex.compile(sPattern, settings.get("flags"));
    this.replacement = settings.get("replacement", "");
    this.all = settings.getAsBoolean("all", true);
}
 
Example #22
Source File: URIPattern.java    From crate with Apache License 2.0 5 votes vote down vote up
private boolean match(String pattern, String value) {
    if (value == null) {
        // If the pattern is empty or matches anything - it's a match
        if (pattern == null || Regex.isMatchAllPattern(pattern)) {
            return true;
        }
    }
    return Regex.simpleMatch(pattern, value);
}
 
Example #23
Source File: XContentMapValues.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a function that filters a document map based on the given include and exclude rules.
 * @see #filter(Map, String[], String[]) for details
 */
public static Function<Map<String, ?>, Map<String, Object>> filter(String[] includes, String[] excludes) {
    CharacterRunAutomaton matchAllAutomaton = new CharacterRunAutomaton(Automata.makeAnyString());

    CharacterRunAutomaton include;
    if (includes == null || includes.length == 0) {
        include = matchAllAutomaton;
    } else {
        Automaton includeA = Regex.simpleMatchToAutomaton(includes);
        includeA = makeMatchDotsInFieldNames(includeA);
        include = new CharacterRunAutomaton(includeA);
    }

    Automaton excludeA;
    if (excludes == null || excludes.length == 0) {
        excludeA = Automata.makeEmpty();
    } else {
        excludeA = Regex.simpleMatchToAutomaton(excludes);
        excludeA = makeMatchDotsInFieldNames(excludeA);
    }
    CharacterRunAutomaton exclude = new CharacterRunAutomaton(excludeA);

    // NOTE: We cannot use Operations.minus because of the special case that
    // we want all sub properties to match as soon as an object matches

    return (map) -> filter(map,
        include, 0,
        exclude, 0,
        matchAllAutomaton);
}
 
Example #24
Source File: MockLogAppender.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void match(LogEvent event) {
    if (event.getLevel().equals(level) && event.getLoggerName().equals(logger) && innerMatch(event)) {
        if (Regex.isSimpleMatchPattern(message)) {
            if (Regex.simpleMatch(message, event.getMessage().getFormattedMessage())) {
                saw = true;
            }
        } else {
            if (event.getMessage().getFormattedMessage().contains(message)) {
                saw = true;
            }
        }
    }
}
 
Example #25
Source File: PatternReplaceCharFilterFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
PatternReplaceCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
    super(indexSettings, name);

    String sPattern = settings.get("pattern");
    if (!Strings.hasLength(sPattern)) {
        throw new IllegalArgumentException("pattern is missing for [" + name + "] char filter of type 'pattern_replace'");
    }
    pattern = Regex.compile(sPattern, settings.get("flags"));
    replacement = settings.get("replacement", ""); // when not set or set to "", use "".
}
 
Example #26
Source File: PatternAnalyzerProvider.java    From crate with Apache License 2.0 5 votes vote down vote up
PatternAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
    super(indexSettings, name, settings);

    final CharArraySet defaultStopwords = CharArraySet.EMPTY_SET;
    boolean lowercase = settings.getAsBoolean("lowercase", true);
    CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);

    String sPattern = settings.get("pattern", "\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/);
    if (sPattern == null) {
        throw new IllegalArgumentException("Analyzer [" + name + "] of type pattern must have a `pattern` set");
    }
    Pattern pattern = Regex.compile(sPattern, settings.get("flags"));

    analyzer = new PatternAnalyzer(pattern, lowercase, stopWords);
}
 
Example #27
Source File: PatternTokenizerFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
PatternTokenizerFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
    super(indexSettings, name, settings);

    String sPattern = settings.get("pattern", "\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/);
    if (sPattern == null) {
        throw new IllegalArgumentException("pattern is missing for [" + name + "] tokenizer of type 'pattern'");
    }

    this.pattern = Regex.compile(sPattern, settings.get("flags"));
    this.group = settings.getAsInt("group", -1);
}
 
Example #28
Source File: DefaultIndexTemplateFilter.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(CreateIndexClusterStateUpdateRequest request, IndexTemplateMetaData template) {
    long tenantId = TenantProperty.ROOT_TENANT_ID;
    LoginUserContext userInfo = (LoginUserContext)request.originalMessage().getHeader(LoginUserContext.USER_INFO_KEY);
    if (userInfo != null) {
        tenantId = userInfo.tenantId();
    }
    if (tenantId != template.templateOwnerTenantId()) {
        return false;
    }
    return Regex.simpleMatch(template.template(), request.index());
}
 
Example #29
Source File: TransportGetSettingsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void masterOperation(GetSettingsRequest request, ClusterState state, ActionListener<GetSettingsResponse> listener) {
    String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
    ImmutableOpenMap.Builder<String, Settings> indexToSettingsBuilder = ImmutableOpenMap.builder();
    for (String concreteIndex : concreteIndices) {
        IndexMetaData indexMetaData = state.getMetaData().index(concreteIndex);
        if (indexMetaData == null) {
            continue;
        }

        Settings settings = SettingsFilter.filterSettings(settingsFilter.getPatterns(), indexMetaData.getSettings());
        if (request.humanReadable()) {
            settings = IndexMetaData.addHumanReadableSettings(settings);
        }
        if (!CollectionUtils.isEmpty(request.names())) {
            Settings.Builder settingsBuilder = Settings.builder();
            for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
                if (Regex.simpleMatch(request.names(), entry.getKey())) {
                    settingsBuilder.put(entry.getKey(), entry.getValue());
                }
            }
            settings = settingsBuilder.build();
        }
        indexToSettingsBuilder.put(concreteIndex, settings);
    }
    listener.onResponse(new GetSettingsResponse(indexToSettingsBuilder.build()));
}
 
Example #30
Source File: IndicesQueryParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected boolean matchesIndices(String currentIndex, String... indices) {
    final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterService.state(), IndicesOptions.lenientExpandOpen(), indices);
    for (String index : concreteIndices) {
        if (Regex.simpleMatch(index, currentIndex)) {
            return true;
        }
    }
    return false;
}