Skip to content

Make timestamp field mapping part of data stream definition #58583

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

Closed
martijnvg opened this issue Jun 26, 2020 · 6 comments · Fixed by #59076
Closed

Make timestamp field mapping part of data stream definition #58583

martijnvg opened this issue Jun 26, 2020 · 6 comments · Fixed by #59076
Labels
:Data Management/Data streams Data streams and their lifecycles :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Data Management Meta label for data/management team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@martijnvg
Copy link
Member

Currently when creating a composable index template with a data stream definition, the timestamp field mapping must be defined too:

PUT /_index_template/logs_data_stream
{
  "index_patterns": [ "logs*" ],
  "data_stream": {
    "timestamp_field": "@timestamp"
  },
  "template": {
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date"
        }
      }
    }
  }
}

The template is much cleaner to read if the mapping itself for timestamp field mapping
is inlined with the data stream definition:

PUT /_index_template/logs_data_stream
{
  "index_patterns": [ "logs*" ],
  "data_stream": {
    "timestamp_field": "@timestamp",
    "timestamp_mapping": {
      "type": "date"
    }
  }
}

Also since most of time, just "type": "date" will be provided, it makes sense to make this the default:

PUT /_index_template/logs_data_stream
{
  "index_patterns": [ "logs*" ],
  "data_stream": {
    "timestamp_field": "@timestamp"
  }
}

In the last two example the backing indices created will have the following mapping:

{
  "_doc": {
    "properties": {
      "@timestamp": {
        "type": "date"
      }
    }
  }
}

The simulate index template api should also include the inserted / generated timestamp field mapping
in the response.

@martijnvg martijnvg added :Search Foundations/Mapping Index mappings, including merging and defining field types team-discuss :Data Management/Data streams Data streams and their lifecycles labels Jun 26, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jun 26, 2020
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Jun 26, 2020
@martijnvg
Copy link
Member Author

This issue was discussed and the fact that the required field mapping has to be configured the template mapping is confusing since the timestamp field name has to be configured in the data stream definition. Especially when getting started with data streams (and Elasticsearch). Also making timestamp field mapping optional, also improves the getting started experience.

Further more it should still be allowed to define the mapping for timestamp field in a component's or composable index's template section. This makes sense if all the other mappings are also defined in the template and otherwise mappings would need to be specified in two places.

martijnvg added a commit to martijnvg/elasticsearch that referenced this issue Jun 28, 2020
Instead of requiring that the field mapping for the timestamp field is defined
in the mapping of the composable index template for data streams, the mapping
should also be definable in the data stream definition itself, since the field
name of the data stream is already defined there.

The timestamp field mapping will be applied when a new backing index of a
data stream is being created.

When a new data stream is created and composable index templates are evaluated then
the mapping are applied in the following order:
* Optional mappings from component templates that are associated with the matching template
* Optional mappings from the matching template itself.
* Optional timestamp field mapping from data stream definition of the matching template.

If no mapping for timestamp field is defined in a component template, composable index template,
data stream definition inside a composable index template then a default mapping for the timestamp
field will be generated at data stream creation time.

Before this commit the field mapping of the timestamp field should be defined as mapping
in the composable template:

```
PUT /_index_template/logs_data_stream
{
  "index_patterns": [ "logs*" ],
  "data_stream": {
    "timestamp_field": "@timestamp"
  },
  "template": {
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date"
        }
      }
    }
  }
}
```

With this commit, the timestamp field mapping may also be defined as part of the data stream definition:

```
PUT /_index_template/logs_data_stream
{
  "index_patterns": [ "logs*" ],
  "data_stream": {
    "timestamp_field": "@timestamp",
    "timestamp_mapping": {
      "type": "date"
    }
  }
}
```

The field mapping is now also optional:

```
PUT /_index_template/logs_data_stream
{
  "index_patterns": [ "logs*" ],
  "data_stream": {
    "timestamp_field": "@timestamp"
  }
}
```

In the latter case the following mapping snippet is used as default:
{"type": "date"}

Closes to elastic#58583
martijnvg added a commit to martijnvg/elasticsearch that referenced this issue Jul 6, 2020
The commit makes the following changes:
* The timestamp field of a data stream definition in a composable
  index template can only be set to '@timestamp'.
* Removed custom data stream timestamp field validation and reuse the validation from `TimestampFieldMapper` and
  instead only check that the _timestamp field mapping has been defined on a backing index of a data stream.
* Moved code that injects _timestamp meta field mapping from `MetadataCreateIndexService#applyCreateIndexRequestWithV2Template58956(...)` method
  to `MetadataIndexTemplateService#collectMappings(...)` method.
* Fixed a bug (elastic#58956) that cases timestamp field validation to be performed
  for each template and instead of the final mappings that is created.

Relates to elastic#58642
Relates to elastic#53100
Closes elastic#58956
Closes elastic#58583
martijnvg added a commit that referenced this issue Jul 8, 2020
The commit makes the following changes:
* The timestamp field of a data stream definition in a composable
  index template can only be set to '@timestamp'.
* Removed custom data stream timestamp field validation and reuse the validation from `TimestampFieldMapper` and
  instead only check that the _timestamp field mapping has been defined on a backing index of a data stream.
* Moved code that injects _timestamp meta field mapping from `MetadataCreateIndexService#applyCreateIndexRequestWithV2Template58956(...)` method
  to `MetadataIndexTemplateService#collectMappings(...)` method.
* Fixed a bug (#58956) that cases timestamp field validation to be performed
  for each template and instead of the final mappings that is created.
* only apply _timestamp meta field if index is created as part of a data stream or data stream rollover,
this fixes a docs test, where a regular index creation matches (logs-*) with a template with a data stream definition.

Relates to #58642
Relates to #53100
Closes #58956
Closes #58583
martijnvg added a commit to martijnvg/elasticsearch that referenced this issue Jul 8, 2020
Backport elastic#59076 of to 7.x branch.

The commit makes the following changes:
* The timestamp field of a data stream definition in a composable
  index template can only be set to '@timestamp'.
* Removed custom data stream timestamp field validation and reuse the validation from `TimestampFieldMapper` and
  instead only check that the _timestamp field mapping has been defined on a backing index of a data stream.
* Moved code that injects _timestamp meta field mapping from `MetadataCreateIndexService#applyCreateIndexRequestWithV2Template58956(...)` method
  to `MetadataIndexTemplateService#collectMappings(...)` method.
* Fixed a bug (elastic#58956) that cases timestamp field validation to be performed
  for each template and instead of the final mappings that is created.
* only apply _timestamp meta field if index is created as part of a data stream or data stream rollover,
this fixes a docs test, where a regular index creation matches (logs-*) with a template with a data stream definition.

Relates to elastic#58642
Relates to elastic#53100
Closes elastic#58956
Closes elastic#58583
martijnvg added a commit that referenced this issue Jul 8, 2020
Backport of #59076 to 7.x branch.

The commit makes the following changes:
* The timestamp field of a data stream definition in a composable
  index template can only be set to '@timestamp'.
* Removed custom data stream timestamp field validation and reuse the validation from `TimestampFieldMapper` and
  instead only check that the _timestamp field mapping has been defined on a backing index of a data stream.
* Moved code that injects _timestamp meta field mapping from `MetadataCreateIndexService#applyCreateIndexRequestWithV2Template58956(...)` method
  to `MetadataIndexTemplateService#collectMappings(...)` method.
* Fixed a bug (#58956) that cases timestamp field validation to be performed
  for each template and instead of the final mappings that is created.
* only apply _timestamp meta field if index is created as part of a data stream or data stream rollover,
this fixes a docs test, where a regular index creation matches (logs-*) with a template with a data stream definition.

Relates to #58642
Relates to #53100
Closes #58956
Closes #58583
@nicholasyin
Copy link

Has timestamp_field been deprecated in 7.15 as I don't find any document mentioning it? If so, how can I specify the timestamp field name?

@danhermann
Copy link
Contributor

Has timestamp_field been deprecated in 7.15 as I don't find any document mentioning it? If so, how can I specify the timestamp field name?

As of now, data streams require the timestamp field to be named @timestamp.

@nicholasyin
Copy link

Has timestamp_field been deprecated in 7.15 as I don't find any document mentioning it? If so, how can I specify the timestamp field name?

As of now, data streams require the timestamp field to be named @timestamp.

K, thanks.

@javanna javanna added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Data streams Data streams and their lifecycles :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Data Management Meta label for data/management team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants