Skip to content

Commit 334fff7

Browse files
authored
Reject mappings that (eventually) set dimension and metric in the same field (#138308) (#138339)
1 parent b1561f2 commit 334fff7

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
@@ -2272,6 +2272,17 @@ public void doValidate(MappingLookup lookup) {
22722272
TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + " can't be configured in nested field [" + fullPath() + "]"
22732273
);
22742274
}
2275+
if (dimension && metricType != null) {
2276+
throw new IllegalArgumentException(
2277+
"["
2278+
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
2279+
+ "] and ["
2280+
+ TimeSeriesParams.TIME_SERIES_METRIC_PARAM
2281+
+ "] cannot be set in conjunction with each other ["
2282+
+ fullPath()
2283+
+ "]"
2284+
);
2285+
}
22752286
}
22762287

22772288
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
@@ -215,4 +215,20 @@ public void testCheckForDuplicatePrioritiesManyElementsDuplicatePriority() throw
215215
);
216216
assertThat(e.getMessage(), containsString("Pass-through object [bar] has a conflicting param [priority=1] with object [foo]"));
217217
}
218+
219+
public void testTimeSeriesDimensionAndMetricConflict() throws IOException {
220+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createMapperService(mapping(b -> {
221+
b.startObject("labels").field("type", "passthrough").field("priority", "0").field("time_series_dimension", "true");
222+
{
223+
b.startObject("properties");
224+
b.startObject("dim").field("type", "long").field("time_series_metric", "counter").endObject();
225+
b.endObject();
226+
}
227+
b.endObject();
228+
})));
229+
assertThat(
230+
e.getMessage(),
231+
containsString("[time_series_dimension] and [time_series_metric] cannot be set in conjunction with each other [labels.dim]")
232+
);
233+
}
218234
}

0 commit comments

Comments
 (0)