Skip to content

Commit f2641c6

Browse files
authored
Reject mappings that (eventually) set dimension and metric in the same field (#138308) (#138338)
1 parent 0a4b690 commit f2641c6

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docs/changelog/138308.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 138308
2+
summary: Reject mappings that (eventually) set dimension and metric in the same field
3+
area: Mapping
4+
type: bug
5+
issues: []

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,17 @@ public void doValidate(MappingLookup lookup) {
23302330
TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + " can't be configured in nested field [" + fullPath() + "]"
23312331
);
23322332
}
2333+
if (dimension && metricType != null) {
2334+
throw new IllegalArgumentException(
2335+
"["
2336+
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
2337+
+ "] and ["
2338+
+ TimeSeriesParams.TIME_SERIES_METRIC_PARAM
2339+
+ "] cannot be set in conjunction with each other ["
2340+
+ fullPath()
2341+
+ "]"
2342+
);
2343+
}
23332344
}
23342345

23352346
private SourceLoader.SyntheticFieldLoader docValuesSyntheticFieldLoader() {

server/src/test/java/org/elasticsearch/index/mapper/PassThroughObjectMapperTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,20 @@ public void testCheckForDuplicatePrioritiesManyElementsDuplicatePriority() throw
266266
);
267267
assertThat(e.getMessage(), containsString("Pass-through object [bar] has a conflicting param [priority=1] with object [foo]"));
268268
}
269+
270+
public void testTimeSeriesDimensionAndMetricConflict() throws IOException {
271+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createMapperService(mapping(b -> {
272+
b.startObject("labels").field("type", "passthrough").field("priority", "0").field("time_series_dimension", "true");
273+
{
274+
b.startObject("properties");
275+
b.startObject("dim").field("type", "long").field("time_series_metric", "counter").endObject();
276+
b.endObject();
277+
}
278+
b.endObject();
279+
})));
280+
assertThat(
281+
e.getMessage(),
282+
containsString("[time_series_dimension] and [time_series_metric] cannot be set in conjunction with each other [labels.dim]")
283+
);
284+
}
269285
}

0 commit comments

Comments
 (0)