# How can i insert the history data into TSDB

**URL:** <https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075>\
**Category:** Elasticsearch\
**Tags:** datastreams\
**Created:** [November 3, 2022, 6:53am UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075 "2022-11-03T06:53:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bo8888](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@bo8888](https://discuss.elastic.co/u/bo8888)\
**Post date:** [November 3, 2022, 6:53am UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075/1 "2022-11-03T06:53:39Z")

</div>

I study [Set up a time series data stream (TSDS) | Elasticsearch Guide [8.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.5/set-up-tsds.html)  
but i insert the data ,found a error

```auto
PUT metrics-weather_sensors-dev/_bulk
{ "create":{ } }
{ "@timestamp": "2099-05-06T16:21:15.000Z", "sensor_id": "HAL-000001", "location": "plains", "temperature": 26.7,"humidity": 49.9 }
{ "create":{ } }
{ "@timestamp": "2099-05-06T16:25:42.000Z", "sensor_id": "SYKENET-000001", "location": "swamp", "temperature": 32.4, "humidity": 88.9 }

```

```auto
          "type": "illegal_argument_exception",
          "reason": "the document timestamp [2099-05-06T16:21:15.000Z] is outside of ranges of currently writable indices [[2022-11-03T03:38:56.000Z,2022-11-03T09:44:56.178Z]]"
        }

```

there is not create indices 2099-\*

if I insert the data of 2021 ,how can set the elasticsearch auth create aaaaa-2021.01.01-000001

thanks

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 3, 2022, 6:55am UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075/2 "2022-11-03T06:55:34Z")

</div>

Did you run through the other steps on that page? What was the outcome of the steps?

---

<div class="post-metadata">

**Author:** ![bo8888](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@bo8888](https://discuss.elastic.co/u/bo8888)\
**Post date:** [November 3, 2022, 7:00am UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075/3 "2022-11-03T07:00:04Z")

</div>

yes,the ILM,setting,mapping,template is all create

---

<div class="post-metadata">

**Author:** ![bo8888](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@bo8888](https://discuss.elastic.co/u/bo8888)\
**Post date:** [November 3, 2022, 7:02am UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075/4 "2022-11-03T07:02:42Z")

</div>

```auto
{
  "template": {
    "settings": {
      "index": {
        "lifecycle": {
          "name": "my-lifecycle-policy"
        },
        "mode": "time_series",
        "codec": "best_compression",
        "routing": {
          "allocation": {
            "include": {
              "_tier_preference": "data_hot"
            }
          }
        },
        "time_series": {
          "end_time": "2022-11-03T10:01:56.000Z",
          "start_time": "2022-11-03T04:01:56.000Z"
        },
        "look_ahead_time": "3h",
        "routing_path": [
          "sensor_id",
          "location"
        ]
      }
    },
    "mappings": {
      "dynamic": "true",
      "dynamic_date_formats": [
        "strict_date_optional_time",
        "yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z"
      ],
      "dynamic_templates": [],
      "date_detection": true,
      "numeric_detection": false,
      "properties": {
        "@timestamp": {
          "type": "date",
          "format": "strict_date_optional_time"
        },
        "humidity": {
          "type": "half_float",
          "time_series_metric": "gauge"
        },
        "location": {
          "type": "keyword",
          "time_series_dimension": true
        },
        "sensor_id": {
          "type": "keyword",
          "time_series_dimension": true
        },
        "temperature": {
          "type": "half_float",
          "time_series_metric": "gauge"
        }
      }
    },
    "aliases": {}
  }
}

```

---

<div class="post-metadata">

**Author:** ![bo8888](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@bo8888](https://discuss.elastic.co/u/bo8888)\
**Post date:** [November 3, 2022, 8:18am UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075/5 "2022-11-03T08:18:24Z")

</div>

it shoud set the start and end time

```auto
"time_series": {
      "end_time": "2099-05-06T16:21:15.000Z",
      "start_time": "2016-05-06T16:21:15.000Z"
    }

```

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [November 3, 2022, 11:56am UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075/6 "2022-11-03T11:56:17Z")

</div>

A tsdb data stream is hard coded to set the `index.time_series.start_time` and `index.time_series.end_time` settings upon creation of the a backing index.

When a data stream is newly created, the first backing index's start\_time setting will be set to: now-look\_ahead\_time (now-3h in your case) and the end\_time setting will be set to: now+look\_ahead\_time (now+3h in your case). Only data that falls into that range is accepted.

So in your example you will need to adjust the `@timestamp` field value that fall into that range in order to get these documents accepted. I think the docs should be improved to highlight this fact.

A tsdb data stream is designed to accept recent metric data (which is based on current time and the index.look\_ahead\_time index setting). As a tsdb data stream gets older and has rolled over then the older backing indices can still accept writes via a data stream (unlike regular data streams). But the most recent backing index is designed to handle recent metric data. The best way to see for what time range a data stream will accept writes, it is best the check the get data stream api. This returns a tsdb data stream's temporal range.

If you're just curious about how well tsdb works for your metric data set, I think it is best to just create a tsdb index (an index with index.mode=time\_series) and then experiment how well your data compresses.

---

<div class="post-metadata">

**Author:** ![bo8888](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@bo8888](https://discuss.elastic.co/u/bo8888)\
**Post date:** [November 3, 2022, 12:02pm UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075/7 "2022-11-03T12:02:40Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 1, 2022, 12:03pm UTC](https://discuss.elastic.co/t/how-can-i-insert-the-history-data-into-tsdb/318075/8 "2022-12-01T12:03:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
