Skip to content

Composable templates: add a default mapping for @timestamp#59244

Merged
andreidan merged 16 commits intoelastic:masterfrom
andreidan:composable-templates-default-timestamp-mapping
Jul 14, 2020
Merged

Composable templates: add a default mapping for @timestamp#59244
andreidan merged 16 commits intoelastic:masterfrom
andreidan:composable-templates-default-timestamp-mapping

Conversation

@andreidan
Copy link
Contributor

This adds a low precedence 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.

Relates to #53100

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.
@andreidan andreidan added >docs General docs changes v8.0.0 :StorageEngine/Data streams Data streams and their lifecycles v7.9.0 labels Jul 8, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-docs (>docs)

@elasticmachine elasticmachine added the Team:Docs Meta label for docs team label Jul 8, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (:Core/Features/Data streams)

@elasticmachine elasticmachine added the Team:Data Management (obsolete) DO NOT USE. This team no longer exists. label Jul 8, 2020
@andreidan andreidan requested review from jrodewig and martijnvg July 8, 2020 17:56
properties:
'@timestamp':
type: date
type: date_nanos
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 is changed to exemplify a custom @timestamp mapping

Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

@jrodewig jrodewig left a comment

Choose a reason for hiding this comment

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

Docs LGTM. I made some minor adjustments to fix a merge conflict introduced with #59225.

@andreidan
Copy link
Contributor Author

@elasticmachine update branch

@martijnvg martijnvg requested a review from jtibshirani July 9, 2020 08:47
Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

Thanks! I left a few comments.

.map(Template::mappings)
.filter(Objects::nonNull)
.collect(Collectors.toList());
.collect(Collectors.toCollection(LinkedList::new));
Copy link
Member

Choose a reason for hiding this comment

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

why linked list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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) {
Copy link
Member

Choose a reason for hiding this comment

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

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 {
Copy link
Member

Choose a reason for hiding this comment

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

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.
Copy link
Member

Choose a reason for hiding this comment

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

maybe include the mapping snippet or that a date field with default options is then used?

properties:
'@timestamp':
type: date
type: date_nanos
Copy link
Member

Choose a reason for hiding this comment

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

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?

@andreidan andreidan requested a review from martijnvg July 9, 2020 11:53
@andreidan
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/1

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

LGTM

@andreidan
Copy link
Contributor Author

@elasticmachine update branch

@andreidan andreidan merged commit 4e72f43 into elastic:master Jul 14, 2020
andreidan added a commit to andreidan/elasticsearch that referenced this pull request Jul 14, 2020
…9244)

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>
andreidan added a commit that referenced this pull request Jul 14, 2020
) (#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>docs General docs changes :StorageEngine/Data streams Data streams and their lifecycles Team:Data Management (obsolete) DO NOT USE. This team no longer exists. Team:Docs Meta label for docs team v7.9.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants