Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSDB: Reject the nested object fields that are configured time_series_dimension #83920

Merged
merged 11 commits into from
Feb 17, 2022
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 @@ -312,7 +312,7 @@ nested dimensions:
reason: message changed in 8.2.0

- do:
catch: /cannot have nested fields when index is in \[index.mode=time_series\]/
catch: /time_series_dimension can't be configured in nested field \[nested.dim\]/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR will change the nested failed message. the field dimension check is before tsdb nested check.

indices.create:
index: test
body:
Expand All @@ -333,3 +333,34 @@ nested dimensions:
dim:
type: keyword
time_series_dimension: true

---
nested fields:
- skip:
version: " - 8.1.99"
reason: message changed in 8.2.0

- do:
catch: /cannot have nested fields when index is in \[index.mode=time_series\]/
indices.create:
index: test
body:
settings:
index:
mode: time_series
routing_path: [dim]
time_series:
start_time: 2021-04-28T00:00:00Z
end_time: 2021-04-29T00:00:00Z
mappings:
properties:
"@timestamp":
type: date
dim:
type: keyword
time_series_dimension: true
nested:
type: nested
properties:
foo:
type: keyword
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 @@ -979,4 +979,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 @@ -25,6 +25,7 @@
import java.io.UncheckedIOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.function.Function;

import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -1380,4 +1381,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", "short", "integer", "byte")))
.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", "short", "integer", "byte")))
.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() + "]"
);
}
}
}