Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/83920.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 83920
summary: "TSDB: Reject the nested object fields that are configured time_series_dimension"
area: TSDB
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ no _tsid in standard indices:
- is_false: fields._tsid # _tsid metadata field must not exist in non-time-series indices

---
nested dimensions:
no nested dimensions:
- skip:
version: all
reason: Awaits fix https://github.com/elastic/elasticsearch/issues/83915
version: " - 8.1.99"
reason: introduced in 8.2.0

- do:
catch: /time_series_dimension can't be configured in nested field \[nested.dim\]/
indices.create:
index: test
body:
Expand All @@ -235,14 +236,3 @@ nested dimensions:
dim:
type: keyword
time_series_dimension: true

- do:
index:
index: test
refresh: true
body:
"@timestamp": "2021-04-28T18:35:24.467Z"
nested:
- dim: foo
- dim: bar
- dim: baz
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,13 @@ protected void indexScriptValues(
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), scriptCompiler, ignoreMalformedByDefault, indexCreatedVersion).dimension(dimension).init(this);
}

@Override
public void doValidate(MappingLookup lookup) {
if (dimension && null != lookup.nestedLookup().getNestedParent(name())) {
throw new IllegalArgumentException(
TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + " can't be configured in nested field [" + name() + "]"
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -955,4 +955,13 @@ protected String contentType() {
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), indexAnalyzers, scriptCompiler).dimension(dimension).init(this);
}

@Override
public void doValidate(MappingLookup lookup) {
if (dimension && null != lookup.nestedLookup().getNestedParent(name())) {
throw new IllegalArgumentException(
TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + " can't be configured in nested field [" + name() + "]"
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1501,4 +1501,13 @@ public FieldMapper.Builder getMergeBuilder() {
.metric(metricType)
.init(this);
}

@Override
public void doValidate(MappingLookup lookup) {
if (dimension && null != lookup.nestedLookup().getNestedParent(name())) {
throw new IllegalArgumentException(
TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + " can't be configured in nested field [" + name() + "]"
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.MapperService.MergeReason;
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
import org.elasticsearch.index.mapper.ObjectMapper.Dynamic;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xcontent.XContentBuilder;
Expand All @@ -23,9 +24,12 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -1380,4 +1384,52 @@ public void testFieldNamesIncludeInRoot() throws Exception {
assertThat(doc.docs().get(4).get("_field_names"), nullValue());
}

public void testNoDimensionNestedFields() {
{
Exception e = expectThrows(IllegalArgumentException.class, () -> createDocumentMapper(mapping(b -> {
b.startObject("nested");
{
b.field("type", "nested");
b.startObject("properties");
{
b.startObject("foo")
.field("type", randomFrom(List.of("keyword", "ip", "long", "double", "unsigned_long")))
.field("time_series_dimension", true)
.endObject();
}
b.endObject();
}
b.endObject();
})));
assertThat(e.getMessage(), containsString("time_series_dimension can't be configured in nested field [nested.foo]"));
}

{
Exception e = expectThrows(IllegalArgumentException.class, () -> createDocumentMapper(mapping(b -> {
b.startObject("nested");
{
b.field("type", "nested");
b.startObject("properties");
{
b.startObject("other").field("type", "keyword").endObject();
b.startObject("object").field("type", "object");
{
b.startObject("properties");
{
b.startObject("foo")
.field("type", randomFrom(List.of("keyword", "ip", "long", "double", "unsigned_long")))
.field("time_series_dimension", true)
.endObject();
}
b.endObject();
}
b.endObject();
}
b.endObject();
}
b.endObject();
})));
assertThat(e.getMessage(), containsString("time_series_dimension can't be configured in nested field [nested.object.foo]"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MappingLookup;
import org.elasticsearch.index.mapper.SimpleMappedFieldType;
import org.elasticsearch.index.mapper.SourceValueFetcher;
import org.elasticsearch.index.mapper.TextSearchInfo;
Expand Down Expand Up @@ -648,4 +649,12 @@ protected static long sortableSignedLongToUnsigned(long value) {
return value ^ MASK_2_63;
}

@Override
public void doValidate(MappingLookup lookup) {
if (dimension && null != lookup.nestedLookup().getNestedParent(name())) {
throw new IllegalArgumentException(
TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + " can't be configured in nested field [" + name() + "]"
);
}
}
}