tencent cloud

Cloud Log Service

Compatible with Elasticsearch API

다운로드
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-11-18 17:30:07
AI 번역

Scenarios

Elasticsearch is an open-source distributed search and analytics engine. CLS is compatible with a subset of its APIs. When migrating from Elasticsearch to CLS, if certain Elasticsearch APIs you previously used fall within CLS's compatibility scope, you can continue to use the same APIs, reducing migration complexity.
CLS's compatible API is based on Elasticsearch version 7.10.

Prerequisites

Indexing must be enabled for logs to use the corresponding DSL. For details, see Index Configuration.

Access mode

Public network address: https://${region}.cls.tencentcs.com/elasticsearch/
Private network address: https://${region}.cls.tencentyun.com/elasticsearch/
where ${region} is the region abbreviation, please use the region where the log topic is located.
The API uses Basic Auth for authentication. Use the SecretId and SecretKey from the API Key as the username and password, respectively.
Note:
It is recommended that you create a separate sub-account and use its SecretId and SecretKey. This account only needs to be granted permissions for the following APIs; for configuration methods, see Sub-Account Authorization.
{
"version": "2.0",
"statement": [
{
"effect": "allow",
"action": [
"cls:SearchLog"
],
"resource": [
"*"
]
}
]
}

Compatible APIs

GET /${topic_id}/_search
POST /${topic_id}/_search
GET /${searchview_id}/_search
POST /${searchview_id}/_search
POST /${topic_id}/_msearch
POST /${searchview_id}/_msearch
POST /_msearch
GET /${topic_id}/_mapping
GET /${searchview_id}/_mapping
POST /${topic_id}/_field_caps
POST /${searchview_id}/_field_caps
Among them:
${topic_id}: log topic ID, equivalent to an index in Elasticsearch. You can obtain it on the Log Topic List page. Only one topic ID can be specified. To query multiple topics at the same time, use ${searchview_id}.
${searchview_id}: search view ID. A search view can contain multiple topics. You need to create the search view in advance through the API.
Note:
Add the Header X-CLS-ES-Protocol-Version: v1 to all requests.

Compatible with DSL

Common parameters

DSL Syntax
Description
from
Pagination start offset. Specifies the record number from which to start returning data. Use with size. A maximum of 10,000 records can be queried using from + size in total.
size
Number of documents returned per page. Controls how many records are displayed on the current page.
sort
Specifies the field for sorting. The field used for sorting must have indexing enabled, and statistics must be enabled in the index configuration.
track_total_hits
Whether to accurately count the total number of matched documents. By default, accurate counting is limited to 10,000.

Query DSL

The fields involved in the following DSL syntax require the index to be enabled in the index configuration.
DSL Syntax
Description
bool
Combine multiple query conditions.
filter
Filter condition that must be met.
should
Optional match condition that functions like OR. It can be used with minimum_should_match to specify the minimum number of should conditions that must be met.
minimum_should_match
Specifies the minimum number of conditions that must be met in bool.should. For example, setting it to 1 means that at least one should condition must be met.
must
Condition that must be met.
must_not
Condition that must not be met.
match
Full-text search.
term
Matches a single value.
terms
Matches multiple values (similar to SQL IN).
range
Range query (for numeric values and similar data).
match_all
Queries all documents.
multi_match
Performs full-text search across multiple fields.
match_phrase
Phrase matching that requires consistent word order.
exists
Checks whether a field exists or is not empty.
ids
Queries by document ID.
prefix
Prefix matching.
wildcard
Wildcard matching (* and ?), but cannot start with a wildcard.
query_string
Advanced query that supports Lucene syntax.
regexp
Regular expression matching.
search_after
Performs deep pagination based on the sort value of the previous page.

Aggregation DSL

The fields involved in the following DSL syntax require the index to be enabled in the index configuration, and statistics to be enabled in the index configuration.
DSL Syntax
Description
avg
Calculate the average value of a numeric field, for example, calculate the average price of products.
sum
Calculate the sum of a numeric field, for example, calculate the total sales for a single day.
max
Obtain the maximum value of a numeric field, for example, find the highest user points.
min
Obtain the minimum value of a numeric field, for example, find the lowest product inventory.
value_count
Count the number of field values, for example, count the number of order IDs.
percentiles
Calculate percentiles to analyze data distribution, for example, calculate the response time in milliseconds within which 95% of requests are completed.
cardinality
Approximate deduplication counting, for example, count the number of unique visitors (UV).
top_hits
Obtain the top documents in each group, for example, view the top 3 products by sales in each category.
terms
Group by field values, similar to SQL GROUP BY, for example, count the number of items by product category.
filter
Filter documents by one filter condition and then perform statistics, for example, count only paid orders.
filters
Group and count by multiple filter conditions separately, for example, count paid and unpaid orders separately.
range
Group by custom numeric ranges, for example, count the number of products in the price ranges 0-100 and 100-500 separately.
date_range
Group by custom date ranges, for example, count orders for this year and last year separately. Only the @timestamp field is supported.
histogram
Group by fixed numeric intervals, for example, count the number of products in each CNY 100 interval.
date_histogram
Group by fixed time intervals, for example, count orders by day, week, or month. Only the @timestamp field is supported.

Field Mapping

Elasticsearch
CLS
Description
@timestamp
__TIMESTAMP__
When the query statement specifies the @timestamp field, the actual query targets the __TIMESTAMP__ field in CLS.

Example

Query Example

Query the first 10 logs where level is WARNING within the time range from 2026-06-09T07:38:04.240 to 2026-06-09T07:53:04.240 (UTC time zone):
curl -X POST "https://ap-guangzhou.cls.tencentcs.com/elasticsearch/34373f59-b5cc-4a54-902a-4a98cade60ea/_search" \\
-H "Content-Type: application/json" \\
-H "X-CLS-ES-Protocol-Version: v1" \\
-u AKIDxxxxxxxxxxxxxxxxxxxxxxxxxx:B9xxxxxxxxxxxxxxxxxxxxxxx \\
-d '{
"track_total_hits": false,
"from": 0,
"size": 10,
"sort": [
{
"@timestamp": {
"order": "desc"
}
}
],
"query": {
"bool": {
"filter": [
{ "match": { "level": "WARNING" } },
{
"range": {
"@timestamp": {
"gte": "2026-06-09T07:38:04.240Z",
"lt": "2026-06-09T07:53:04.240Z"
}
}
}
]
}
}
}'

Aggregation Example

Query logs containing the keyword user-service within the time range from 2026-06-09T07:38:04.240 to 2026-06-09T07:53:04.240 (UTC time zone), and count the number of logs grouped by level:
curl -X POST "https://ap-guangzhou.cls.tencentcs.com/elasticsearch/34373f59-b5cc-4a54-902a-4a98cade60ea/_search" \\
-H "Content-Type: application/json" \\
-H "X-CLS-ES-Protocol-Version: v1" \\
-u AKIDxxxxxxxxxxxxxxxxxxxxxxxxxx:B9xxxxxxxxxxxxxxxxxxxxxxx \\
-d '{
"size": 0,
"query": {
"bool": {
"filter": [
{
"multi_match": {
"type": "best_fields",
"query": "user-service",
"lenient": true
}
},
{
"range": {
"@timestamp": {
"gte": "2026-06-09T07:38:04.240Z",
"lt": "2026-06-09T07:53:04.240Z"
}
}
}
]
}
},
"aggs": {
"level_distribution": {
"terms": {
"field": "level",
"size": 100,
"min_doc_count": 1
}
}
}
}'

Kibana Compatibility

For details, see Using CLS with Kibana.


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백