Composable templates: add a default mapping for @timestamp#59244
Conversation
This adds a low precendece mapping for the `@timestamp` field with type `date`. This will aid with the bootstrapping of data streams as a timestamp mapping can be omitted when nanos precision is not needed.
|
Pinging @elastic/es-docs (>docs) |
|
Pinging @elastic/es-core-features (:Core/Features/Data streams) |
| properties: | ||
| '@timestamp': | ||
| type: date | ||
| type: date_nanos |
There was a problem hiding this comment.
This is changed to exemplify a custom @timestamp mapping
There was a problem hiding this comment.
Maybe in the Create data stream yaml test, also check that mapping for the backing index of each data streams to have the correct mapping?
server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java
Outdated
Show resolved
Hide resolved
|
@elasticmachine update branch |
martijnvg
left a comment
There was a problem hiding this comment.
Thanks! I left a few comments.
| .map(Template::mappings) | ||
| .filter(Objects::nonNull) | ||
| .collect(Collectors.toList()); | ||
| .collect(Collectors.toCollection(LinkedList::new)); |
There was a problem hiding this comment.
because we insert a mapping on the first position below (adding the default @timestamp). That takes linear time with ArrayList as opposed to constant time with the LinkedList. We also don't random access the mappings list but always iterate it on, so it seems like the LinkedList is a better fit for the current use cases.
| Optional.ofNullable(template.template()) | ||
| .map(Template::mappings) | ||
| .ifPresent(mappings::add); | ||
| if (template.getDataStreamTemplate() != null) { |
There was a problem hiding this comment.
I think we need to move this side the body of if (indexName.startsWith(DataStream.BACKING_INDEX_PREFIX)) {,
because this should only be applied when a backing index is created (and otherwise a regular create index call and if a template matches with a 'data_stream' definition would get this mapping applied as well).
| equalTo(Map.of("_doc", Map.of("properties", Map.of("field2", Map.of("type", "integer")))))); | ||
| } | ||
|
|
||
| public void testUserDefinedMappingTakesPrecedenceOverDefault() throws Exception { |
There was a problem hiding this comment.
These are good tests. Maybe also add another test that tests that a user adds a mapping for @timestamp in a composable index template?
|
|
||
| * An optional field mapping for the `@timestamp` field. Both the <<date,`date`>> and | ||
| <<date_nanos,`date_nanos`>> field data types are supported. If no mapping is specified, | ||
| the <<date,`date`>> field data type is used by default. |
There was a problem hiding this comment.
maybe include the mapping snippet or that a date field with default options is then used?
| properties: | ||
| '@timestamp': | ||
| type: date | ||
| type: date_nanos |
There was a problem hiding this comment.
Maybe in the Create data stream yaml test, also check that mapping for the backing index of each data streams to have the correct mapping?
|
@elasticmachine run elasticsearch-ci/1 |
|
@elasticmachine update branch |
) (#59510) This adds a low precendece mapping for the `@timestamp` field with type `date`. This will aid with the bootstrapping of data streams as a timestamp mapping can be omitted when nanos precision is not needed. (cherry picked from commit 4e72f43) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
This adds a low precedence mapping for the
@timestampfield withtype
date.This will aid with the bootstrapping of data streams as a timestamp
mapping can be omitted when nanos precision is not needed.
Relates to #53100