Skip to content

Commit 33ebf40

Browse files
authored
Reject mappings that (eventually) set dimension and metric in the same field (#138308)
1 parent ab7fcd4 commit 33ebf40

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
@@ -2316,6 +2316,17 @@ public void doValidate(MappingLookup lookup) {
23162316
TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + " can't be configured in nested field [" + fullPath() + "]"
23172317
);
23182318
}
2319+
if (dimension && metricType != null) {
2320+
throw new IllegalArgumentException(
2321+
"["
2322+
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
2323+
+ "] and ["
2324+
+ TimeSeriesParams.TIME_SERIES_METRIC_PARAM
2325+
+ "] cannot be set in conjunction with each other ["
2326+
+ fullPath()
2327+
+ "]"
2328+
);
2329+
}
23192330
}
23202331

23212332
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
@@ -265,4 +265,20 @@ public void testCheckForDuplicatePrioritiesManyElementsDuplicatePriority() throw
265265
);
266266
assertThat(e.getMessage(), containsString("Pass-through object [bar] has a conflicting param [priority=1] with object [foo]"));
267267
}
268+
269+
public void testTimeSeriesDimensionAndMetricConflict() throws IOException {
270+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createMapperService(mapping(b -> {
271+
b.startObject("labels").field("type", "passthrough").field("priority", "0").field("time_series_dimension", "true");
272+
{
273+
b.startObject("properties");
274+
b.startObject("dim").field("type", "long").field("time_series_metric", "counter").endObject();
275+
b.endObject();
276+
}
277+
b.endObject();
278+
})));
279+
assertThat(
280+
e.getMessage(),
281+
containsString("[time_series_dimension] and [time_series_metric] cannot be set in conjunction with each other [labels.dim]")
282+
);
283+
}
268284
}

0 commit comments

Comments
 (0)