You can call the UpdateTimeseriesMeta operation to update the metadata of multiple time series at the same time. If the time series metadata that you want to update does not exist, the time series metadata is added.
Prerequisites
A client is initialized. For more information, see Initialize a Tablestore client.
Parameters
The timeseriesMeta parameter specifies the metadata of a time series. Each timeseriesMeta parameter consists of the timeseriesKey and attributes parameters. The following table describes the parameters.
Parameter | Required | Description |
timeseriesKey | Yes | The identifiers of the time series, which include the following items:
Important If you are not sure about information of the time series that you want to query, such as the metric name and data source, you can call the QueryTimeseriesMeta operation to retrieve time series based on various conditions. For more information, see Retrieve time series. |
attributes | Yes | The attributes of the time series. The value consists of one or more key-value pairs of the String type. |
Example
The following sample code provides an example on how to update the attributes information of time series:
func UpdateTimeseriesMetaSample(tsClient *tablestore.TimeseriesClient, timeseriesTableName string) {
fmt.Println("[Info]: Begin to update timeseries meta!")
updateTimeseriesMetaRequest := tablestore.NewUpdateTimeseriesMetaRequest(timeseriesTableName)
timeseriesKey := tablestore.NewTimeseriesKey()
timeseriesKey.SetMeasurementName("NETWORK")
timeseriesKey.SetDataSource("127.0.0.1")
timeseriesKey.AddTag("City" , "Hangzhou")
timeseriesKey.AddTag("Region" , "Xihu")
timeseriesMeta := tablestore.NewTimeseriesMeta(timeseriesKey)
//timeseriesMeta.SetUpdateTimeInUs(96400)
timeseriesMeta.AddAttribute("NewRegion" , "Yuhang")
timeseriesMeta.AddAttribute("NewCity" , "Shanghai")
updateTimeseriesMetaRequest.AddTimeseriesMetas(timeseriesMeta)
updateTimeseriesMetaResponse , err := tsClient.UpdateTimeseriesMeta(updateTimeseriesMetaRequest)
if err != nil {
fmt.Println("[Error]: Update timeseries meta failed with error: " , err)
return
}
if len(updateTimeseriesMetaResponse.GetFailedRowResults()) > 0 {
fmt.Println("[Error]: Update timeseries meta failed row: ")
for i := 0; i < len(updateTimeseriesMetaResponse.GetFailedRowResults()); i++ {
fmt.Println("[Error]: " , updateTimeseriesMetaResponse.GetFailedRowResults()[i].Index , updateTimeseriesMetaResponse.GetFailedRowResults()[i].Error)
}
}
fmt.Println("[Info]: UpdateTimeseriesMetaSample finished!")
}References
To view the updated time series attributes, you can retrieve time series. For more information, see Retrieve time series.