diff --git a/quesma/elasticsearch/index_resolver.go b/quesma/elasticsearch/index_resolver.go index 35e9ac166..9d8e141cc 100644 --- a/quesma/elasticsearch/index_resolver.go +++ b/quesma/elasticsearch/index_resolver.go @@ -42,6 +42,13 @@ func NewIndexResolver(elasticsearchUrl string) IndexResolver { } } +func NormalizePattern(p string) string { + if p == "_all" { + return "*" + } + return p +} + func (im *indexResolver) Resolve(indexPattern string) (Sources, bool, error) { req, _ := http.NewRequest("GET", im.Url+"/_resolve/index/"+indexPattern+"?expand_wildcards=open", bytes.NewBuffer([]byte{})) response, err := im.httpClient.Do(req) diff --git a/quesma/quesma/matchers.go b/quesma/quesma/matchers.go index f2f63b8dc..b6e757088 100644 --- a/quesma/quesma/matchers.go +++ b/quesma/quesma/matchers.go @@ -34,7 +34,7 @@ func matchedAgainstBulkBody(configuration config.QuesmaConfiguration) func(m map func matchedAgainstPattern(configuration config.QuesmaConfiguration) mux.MatchPredicate { return func(m map[string]string, _ string) bool { - indexPattern := m["index"] + indexPattern := elasticsearch.NormalizePattern(m["index"]) if elasticsearch.IsInternalIndex(indexPattern) { logger.Debug().Msgf("index %s is an internal Elasticsearch index, skipping", indexPattern) return false @@ -52,7 +52,7 @@ func matchedAgainstPattern(configuration config.QuesmaConfiguration) mux.MatchPr for _, pattern := range indexPatterns { for _, indexName := range configuration.IndexConfig { - if config.MatchName(preprocessPattern(pattern), indexName.Name) { + if config.MatchName(elasticsearch.NormalizePattern(pattern), indexName.Name) { if configuration.IndexConfig[indexName.Name].Enabled { return true } @@ -62,7 +62,7 @@ func matchedAgainstPattern(configuration config.QuesmaConfiguration) mux.MatchPr return false } else { for _, index := range configuration.IndexConfig { - pattern := preprocessPattern(indexPattern) + pattern := elasticsearch.NormalizePattern(indexPattern) if config.MatchName(pattern, index.Name) { if indexConfig, exists := configuration.IndexConfig[index.Name]; exists { return indexConfig.Enabled @@ -74,10 +74,3 @@ func matchedAgainstPattern(configuration config.QuesmaConfiguration) mux.MatchPr } } } - -func preprocessPattern(p string) string { - if p == "_all" { - return "*" - } - return p -} diff --git a/quesma/quesma/router.go b/quesma/quesma/router.go index af319ba2a..b0b0aa910 100644 --- a/quesma/quesma/router.go +++ b/quesma/quesma/router.go @@ -58,7 +58,7 @@ func configureRouter(cfg config.QuesmaConfiguration, lm *clickhouse.LogManager, }) router.RegisterPathMatcher(routes.ResolveIndexPath, []string{"GET"}, always(), func(ctx context.Context, body string, _ string, params map[string]string) (*mux.Result, error) { - pattern := params["index"] + pattern := elasticsearch.NormalizePattern(params["index"]) if elasticsearch.IsIndexPattern(pattern) { // todo avoid creating new instances all the time sources, found, err := elasticsearch.NewIndexResolver(cfg.Elasticsearch.Url.String()).Resolve(pattern) @@ -78,7 +78,7 @@ func configureRouter(cfg config.QuesmaConfiguration, lm *clickhouse.LogManager, }) definitions.Range( func(name string, table *clickhouse.Table) bool { - if config.MatchName(preprocessPattern(pattern), name) { + if config.MatchName(elasticsearch.NormalizePattern(pattern), name) { sources.DataStreams = append(sources.DataStreams, elasticsearch.DataStream{ Name: name, BackingIndices: []string{name}, @@ -91,7 +91,7 @@ func configureRouter(cfg config.QuesmaConfiguration, lm *clickhouse.LogManager, return resolveIndexResult(sources), nil } else { - if config.MatchName(preprocessPattern(pattern), pattern) { + if config.MatchName(elasticsearch.NormalizePattern(pattern), pattern) { definitions := lm.GetTableDefinitions() if definitions.Has(pattern) { return resolveIndexResult(elasticsearch.Sources{