Skip to content

Commit a2d149e

Browse files
committed
Reject mappings that (eventually) set dimension and metric in the same field (elastic#138308)
1 parent 7cdb08d commit a2d149e

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

22762287
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)