Writes time series data to a time series index in Alibaba Cloud Elasticsearch using the InfluxDB line protocol.
Prerequisites
Before you begin, ensure that you have:
An Elasticsearch V7.10 cluster with a kernel version of V1.8.0 or later. For setup instructions, see Create an Alibaba Cloud Elasticsearch cluster
Request syntax
POST /_time_stream/influx/write?db={index}&precision=ns
{infludb lines data}Request parameters
| Parameter | Required | Description |
|---|---|---|
db | Yes | The name of the time series index to write data to. |
precision | No | The timestamp precision. Valid values: n, ns, u, ms, s, m, and h. Default: ns. |
Usage notes
InfluxDB line protocol syntax
The request body must be formatted as InfluxDB line protocol. For the full specification, see Line protocol in the InfluxDB documentation.
// Syntax
<measurement>[,<tag_key>=<tag_value>[,<tag_key>=<tag_value>]] <field_key>=<field_value>[,<field_key>=<field_value>] [<timestamp>]
// Example
myMeasurement,tag1=value1,tag2=value2 fieldKey="fieldValue" 1556813561098000000How measurement names map to Elasticsearch fields
When data is written to a time series index, the measurement name is stored as a field named measurement inside the labels object.
measurement in labels, the measurement name overwrites that field's value.The following example shows how InfluxDB data maps to an Elasticsearch document.
InfluxDB input:
testInflux,label1=label_value1 metric1=0.5Elasticsearch output:
{
"@timestamp": 1669972652000,
"labels": {
"measurement": "testInflux",
"label1": "label_value1"
},
"metrics": {
"metric1": 0.5
}
}After the data is written, query it using the Elasticsearch search APIs or the Prometheus APIs integrated with aliyun-timestream.
Examples
Write data
curl -i --user "user:password" "http://xxx:9200/_time_stream/influx/write?db=test_stream" -d "testInflux,label1=label_value1 metric1=0.5"Response
A successful write returns HTTP 204 with no response body:
HTTP/1.1 204 No ContentIf the write fails, the response format follows the InfluxDB write API error format.