All Products
Search
Document Center

Tablestore:Delete time series

Last Updated:Apr 25, 2025

You can call the DeleteTimeseriesMeta operation to delete the metadata of multiple time series in a batch.

Prerequisites

A client is initialized. For more information, see Initialize a Tablestore client.

Parameters

Time series identifiers are used to identify a time series. You can specify time series identifiers of multiple time series to delete the metadata of multiple time series. The following table describes the parameters.

Parameter

Description

timeseriesKey

The identifiers of the time series, which include the following items:

  • measurementName: the metric name of the time series.

  • dataSource: the data source of the time series. You can leave this item empty.

  • tags: the tags of the time series. The tags are multiple key-value pairs of the String type.

Example

The following sample code provides an example on how to delete specific time series from a time series table:

func DeleteTimeseriesMetaSample(tsClient *tablestore.TimeseriesClient, timeseriesTableName string) {
    fmt.Println("[Info]: Begin to delete timeseries meta: ", timeseriesTableName)
    // Construct a request to delete time series metadata.
    deleteTimeseriesMetaRequest := tablestore.NewDeleteTimeseriesMetaRequest(timeseriesTableName) 
    for i := 0; i < 10; i++ {
        timeseriesKey := tablestore.NewTimeseriesKey()
        timeseriesKey.SetMeasurementName("cpu")
        timeseriesKey.SetDataSource("host_" + strconv.Itoa(i))
        timeseriesKey.AddTag("region", "hangzhou")
        timeseriesKey.AddTag("os", "Ubuntu16.04")
        deleteTimeseriesMetaRequest.AddTimeseriesKeys(timeseriesKey)
    }
    deleteTimeseriesMetaResponse, err := tsClient.DeleteTimeseriesMeta(deleteTimeseriesMetaRequest)
    if err != nil {
        fmt.Println("[Error]: Failed to delete timeseries meta with error: ", err)
        return
    }
    fmt.Println("[Info]: DeleteTimeseriesMeta finished! RequestId: ", deleteTimeseriesMetaResponse.RequestId)
}