Skip to content

Commit ab6de24

Browse files
authored
TSDB: routingPath object type check improvement (#83310)
Only reject mappings who's object fields exactly match routing_path. If the fields match some pattern in routing_path that's ok - so long as the fields inside follow all of the routing_path rules.
1 parent e4cc73c commit ab6de24

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

docs/changelog/83310.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 83310
2+
summary: "TSDB: routingPath object type check improvement"
3+
area: TSDB
4+
type: enhancement
5+
issues: []

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/tsdb/20_mapping.yml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ ecs style:
5454
time_series_metric: gauge
5555

5656
---
57-
top level dim object:
57+
top level wildcard dim object:
5858
- skip:
59-
version: " - 8.0.99"
60-
reason: introduced in 8.1.0
59+
version: " - 8.1.99"
60+
reason: routing_path object type check improve in 8.2.0
6161

6262
- do:
6363
indices.create:
@@ -66,7 +66,7 @@ top level dim object:
6666
settings:
6767
index:
6868
mode: time_series
69-
routing_path: [dim.*]
69+
routing_path: [dim*]
7070
time_series:
7171
start_time: 2021-04-28T00:00:00Z
7272
end_time: 2021-04-29T00:00:00Z
@@ -111,6 +111,39 @@ top level dim object:
111111
type: double
112112
time_series_metric: gauge
113113

114+
---
115+
exact match object type:
116+
- skip:
117+
version: " - 8.1.99"
118+
reason: routing_path object type check improve in 8.2.0
119+
120+
- do:
121+
catch: '/All fields that match routing_path must be keywords with \[time_series_dimension: true\] and without the \[script\] parameter. \[dim\] was \[object\]./'
122+
indices.create:
123+
index: tsdb_index
124+
body:
125+
settings:
126+
index:
127+
mode: time_series
128+
routing_path: [dim]
129+
time_series:
130+
start_time: 2021-04-28T00:00:00Z
131+
end_time: 2021-04-29T00:00:00Z
132+
number_of_replicas: 0
133+
number_of_shards: 2
134+
mappings:
135+
properties:
136+
"@timestamp":
137+
type: date
138+
dim:
139+
properties:
140+
metricset:
141+
type: keyword
142+
time_series_dimension: true
143+
uid:
144+
type: keyword
145+
time_series_dimension: true
146+
114147
---
115148
non keyword matches routing_path:
116149
- skip:

server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.elasticsearch.index.mapper;
1010

1111
import org.elasticsearch.common.compress.CompressedXContent;
12-
import org.elasticsearch.common.regex.Regex;
1312
import org.elasticsearch.index.IndexSettings;
1413

1514
import java.util.List;
@@ -104,7 +103,8 @@ public void validate(IndexSettings settings, boolean checkLimits) {
104103
mappingLookup.getFieldType(match).validateMatchedRoutingPath();
105104
}
106105
for (String objectName : mappingLookup.objectMappers().keySet()) {
107-
if (Regex.simpleMatch(path, objectName)) {
106+
// object type is not allowed in the routing paths
107+
if (path.equals(objectName)) {
108108
throw new IllegalArgumentException(
109109
"All fields that match routing_path must be keywords with [time_series_dimension: true] "
110110
+ "and without the [script] parameter. ["

server/src/test/java/org/elasticsearch/index/TimeSeriesModeTests.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,22 @@ public void testValidateAliasWithSearchRouting() {
144144
assertThat(e.getMessage(), equalTo("routing is forbidden on CRUD operations that target indices in [index.mode=time_series]"));
145145
}
146146

147-
public void testRoutingPathMatchesObject() {
148-
Settings s = getSettings(randomBoolean() ? "dim.o" : "dim.*");
147+
public void testRoutingPathMatchesObject() throws IOException {
148+
Settings s = getSettings("dim.o*");
149+
createMapperService(s, mapping(b -> {
150+
b.startObject("dim").startObject("properties");
151+
{
152+
b.startObject("o").startObject("properties");
153+
b.startObject("inner_dim").field("type", "keyword").field("time_series_dimension", true).endObject();
154+
b.endObject().endObject();
155+
}
156+
b.startObject("dim").field("type", "keyword").field("time_series_dimension", true).endObject();
157+
b.endObject().endObject();
158+
}));
159+
}
160+
161+
public void testRoutingPathEqualsObjectNameError() {
162+
Settings s = getSettings("dim.o");
149163
Exception e = expectThrows(IllegalArgumentException.class, () -> createMapperService(s, mapping(b -> {
150164
b.startObject("dim").startObject("properties");
151165
{

0 commit comments

Comments
 (0)