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: improve error message for nested fields #83837

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ add time series mappings:
can't shadow dimensions:
- skip:
version: " - 8.0.99"
reason: introduced in 8.1.0 to be backported to 8.0.0
reason: introduced in 8.1.0

- do:
indices.create:
Expand Down Expand Up @@ -118,7 +118,7 @@ can't shadow dimensions:
can't shadow metrics:
- skip:
version: " - 8.0.99"
reason: introduced in 8.1.0 to be backported to 8.0.0
reason: introduced in 8.1.0

- do:
indices.create:
Expand Down Expand Up @@ -214,3 +214,35 @@ no _tsid in standard indices:
- is_false: fields.metricset.keyword.non_searchable_indices
- is_false: fields.metricset.keyword.non_aggregatable_indices
- is_false: fields._tsid # _tsid metadata field must not exist in non-time-series indices

---
nested dimensions:
- skip:
version: " - 8.0.99"
reason: introduced in 8.1.0

- do:
indices.create:
index: test
body:
mappings:
properties:
"@timestamp":
type: date
nested:
type: nested
properties:
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 @@ -271,3 +271,32 @@ runtime field matching routing path:
- '{"@timestamp": "2021-04-28T18:50:04.467Z", "dim": {"foo": {"bar": "a"}}}'
- match: {items.0.index.error.reason: "All fields matching [routing_path] must be mapped but [dim.foo] was declared as [dynamic: false]"}
- match: {items.1.index.error.reason: "All fields matching [routing_path] must be mapped but [dim.foo] was declared as [dynamic: false]"}

---
nested dimensions:
- 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: [nested.*]
time_series:
start_time: 2021-04-28T00:00:00Z
end_time: 2021-04-29T00:00:00Z
mappings:
properties:
"@timestamp":
type: date
nested:
type: nested
properties:
dim:
type: keyword
time_series_dimension: true
4 changes: 4 additions & 0 deletions server/src/main/java/org/elasticsearch/index/IndexMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MappingLookup;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.NestedLookup;
import org.elasticsearch.index.mapper.RoutingFieldMapper;
import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper;

Expand Down Expand Up @@ -110,6 +111,9 @@ private String error(Setting<?> unsupported) {

@Override
public void validateMapping(MappingLookup lookup) {
if (lookup.nestedLookup() != NestedLookup.EMPTY) {
throw new IllegalArgumentException("cannot have nested fields when index is in " + tsdbMode());
}
if (((RoutingFieldMapper) lookup.getMapper(RoutingFieldMapper.NAME)).required()) {
throw new IllegalArgumentException(routingRequiredBad());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void validate(IndexSettings settings, boolean checkLimits) {
);
}
}
settings.getMode().validateMapping(mappingLookup);
if (settings.getIndexSortConfig().hasIndexSort() && mappers().nestedLookup() != NestedLookup.EMPTY) {
throw new IllegalArgumentException("cannot have nested fields when index sort is activated");
}
Expand All @@ -117,6 +118,5 @@ public void validate(IndexSettings settings, boolean checkLimits) {
if (checkLimits) {
this.mappingLookup.checkLimits(settings);
}
settings.getMode().validateMapping(mappingLookup);
}
}