All Products
Search
Document Center

Elasticsearch:Integrate aliyun-timestream with the InfluxDB line protocol

Last Updated:Aug 23, 2023

aliyun-timestream allows you to use the InfluxDB line protocol to synchronize data from InfluxDB to time series indexes in Elasticsearch. This topic describes the API that can be used to synchronize data from InfluxDB to time series indexes in Elasticsearch. This topic also describes the usage notes of the API and provides usage examples.

Prerequisites

An Elasticsearch V7.10 cluster of the Standard Edition is created. The kernel version of the cluster is V1.8.0 or later. For more information, see Create an Alibaba Cloud Elasticsearch cluster.

Request syntax

POST /_time_stream/influx/write?db={index}&precision=ns
{infludb lines data}

Request parameters

ParameterDescription
dbRequired. This parameter specifies the name of the time series index to which you want to write data.
precisionOptional. The precision parameter. Valid values: n, ns, u, ms, s, m, and h. If you do not configure this parameter, the default value ns is used.

Usage notes

The following code shows the syntax of the InfluxDB line protocol. For more information about the line protocol, see Line protocol in the documentation for InfluxDB.
// 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" 1556813561098000000
Note For the data that is synchronized from InfluxDB to a time series index in Elasticsearch by using the InfluxDB line protocol, the actual name of the measurement is presented by a field named measurement (Field 1) in the labels parameter. If the name of an existing field (Field 2) contained in the labels parameter is also measurement, the value of Field 1 overwrites the value of Field 2.
The following code provides examples of the data format in InfluxDB and the data format after the data is written to Elasticsearch.
  • Data in InfluxDB
    testInflux,label1=label_value1 metric1=0.5
  • Data that is written to Elasticsearch
    {
      "@timestamp": 1669972652000,
      "labels": {
        "measurement": "testInflux",
        "label1": "label_value1"
      },
      "metrics": {
        "metric1": 0.5
      }
    }

    You can use the search APIs of open source Elasticsearch or Prometheus APIs that are integrated with aliyun-timestream to query the data that is synchronized from InfluxDB to Elasticsearch by using the InfluxDB line protocol.

Examples

Sample request

curl -i --user "user:password" "http://xxx:9200/_time_stream/influx/write?db=test_stream" -d "testInflux,label1=label_value1 metric1=0.5"

Sample response

HTTP/1.1 204 No Content

If the data is successfully written to Elasticsearch, the body of the response is displayed as No Content, and the HTTP status code 204 is returned. If the data fails to be written to Elasticsearch, the response is the same as the response returned when data fails to be written by using the InfluxDB write API.