diff --git a/docs/changelog/138308.yaml b/docs/changelog/138308.yaml new file mode 100644 index 0000000000000..40243ca2659c6 --- /dev/null +++ b/docs/changelog/138308.yaml @@ -0,0 +1,5 @@ +pr: 138308 +summary: Reject mappings that (eventually) set dimension and metric in the same field +area: Mapping +type: bug +issues: [] diff --git a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index 2820ae2cd56f0..65d3390309338 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -2316,6 +2316,17 @@ public void doValidate(MappingLookup lookup) { TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + " can't be configured in nested field [" + fullPath() + "]" ); } + if (dimension && metricType != null) { + throw new IllegalArgumentException( + "[" + + TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + + "] and [" + + TimeSeriesParams.TIME_SERIES_METRIC_PARAM + + "] cannot be set in conjunction with each other [" + + fullPath() + + "]" + ); + } } private SourceLoader.SyntheticFieldLoader docValuesSyntheticFieldLoader() { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/PassThroughObjectMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/PassThroughObjectMapperTests.java index c6764c34a1abb..0edcbeccff8eb 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/PassThroughObjectMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/PassThroughObjectMapperTests.java @@ -265,4 +265,20 @@ public void testCheckForDuplicatePrioritiesManyElementsDuplicatePriority() throw ); assertThat(e.getMessage(), containsString("Pass-through object [bar] has a conflicting param [priority=1] with object [foo]")); } + + public void testTimeSeriesDimensionAndMetricConflict() throws IOException { + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createMapperService(mapping(b -> { + b.startObject("labels").field("type", "passthrough").field("priority", "0").field("time_series_dimension", "true"); + { + b.startObject("properties"); + b.startObject("dim").field("type", "long").field("time_series_metric", "counter").endObject(); + b.endObject(); + } + b.endObject(); + }))); + assertThat( + e.getMessage(), + containsString("[time_series_dimension] and [time_series_metric] cannot be set in conjunction with each other [labels.dim]") + ); + } }