Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix routing_path when template has multiple path_match and multi-fields #104418

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/104418.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 104418
summary: Fix `routing_path` when template has multiple `path_match` and multi-fields
area: TSDB
type: bug
issues:
- 104400
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.io.UncheckedIOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -182,7 +181,8 @@ private List<String> findRoutingPaths(String indexName, Settings allSettings, Li
// Since FieldMapper.parse modifies the Map passed in (removing entries for "type"), that means
// that only the first pathMatch passed in gets recognized as a time_series_dimension. To counteract
// that, we wrap the mappingSnippet in a new HashMap for each pathMatch instance.
felixbarny marked this conversation as resolved.
Show resolved Hide resolved
.parse(pathMatch, new HashMap<>(mappingSnippet), parserContext)
// Note that a shallow copy of the map is not enough if there are multi-fields.
.parse(pathMatch, template.mappingForName(templateName, KeywordFieldMapper.CONTENT_TYPE), parserContext)
felixbarny marked this conversation as resolved.
Show resolved Hide resolved
.build(MapperBuilderContext.root(false, false));
extractPath(routingPaths, mapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,55 @@ public void testGenerateRoutingPathFromDynamicTemplateWithMultiplePathMatchEntri
assertEquals(3, routingPathList.size());
}

public void testGenerateRoutingPathFromDynamicTemplateWithMultiplePathMatchEntriesMultiFields() throws Exception {
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
String mapping = """
{
"_doc": {
"dynamic_templates": [
{
"labels": {
"path_match": ["xprometheus.labels.*", "yprometheus.labels.*"],
"mapping": {
"type": "keyword",
"time_series_dimension": true,
"fields": {
"text": {
"type": "text"
}
}
}
}
}
],
"properties": {
"host": {
"properties": {
"id": {
"type": "keyword",
"time_series_dimension": true
}
}
},
"another_field": {
"type": "keyword"
}
}
}
}
""";
Settings result = generateTsdbSettings(mapping, now);
assertThat(result.size(), equalTo(3));
assertThat(IndexSettings.TIME_SERIES_START_TIME.get(result), equalTo(now.minusMillis(DEFAULT_LOOK_BACK_TIME.getMillis())));
assertThat(IndexSettings.TIME_SERIES_END_TIME.get(result), equalTo(now.plusMillis(DEFAULT_LOOK_AHEAD_TIME.getMillis())));
assertThat(
IndexMetadata.INDEX_ROUTING_PATH.get(result),
containsInAnyOrder("host.id", "xprometheus.labels.*", "yprometheus.labels.*")
);
List<String> routingPathList = IndexMetadata.INDEX_ROUTING_PATH.get(result);
assertEquals(3, routingPathList.size());
}

public void testGenerateRoutingPathFromDynamicTemplate_templateWithNoPathMatch() throws Exception {
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
String mapping = """
Expand Down