Skip to content

DQL Data Query



POST /api/v1/df/query_data_v1
GET /api/v1/df/query_data_v1

Overview

Retrieve DQL or PromQL data in query batches. POST also supports queries against QueryHub data sources.

Before Calling and Usage Steps

For regular DQL or PromQL, POST JSON is recommended; GET places the same JSON object in a URL-encoded body. QueryHub is submitted only via POST JSON, and a data source that supports the query language must be enabled in the current workspace. A synchronous mixed batch can contain up to 20 items and at most one QueryHub query. If you need multiple QueryHub queries, use Asynchronous Query.

Replace the measurements and fields in the examples with data collected in the workspace; you can obtain them from Measurement List and Measurement Schema. Replace the time range with the period in which the data resides. When parsing the response, check warnings or query_error for each item, and use that item's own cursor for continuation pages.

Request Headers

Parameter Name Type Required Description
DF-API-KEY string Y OpenAPI Key for the current workspace.
Example: <DF-API-KEY>
How to obtain or enter: Obtain credentials with query permissions from API Key Management in the target workspace.

Query Request Parameters

Parameter Name Type Required Description
body string The complete JSON object string used for GET queries. If omitted and no other query is submitted, an empty result is returned.
Example: {"queries":[{"qtype":"dql","query":{"q":"M::`cpu`:(`usage_idle`)","timeRange":[1785427200000,1785430800000],"limit":5}}]}
How to obtain or enter: Serialize the query object once, then URL-encode it, for example with curl --data-urlencode.

Body Request Parameters

Parameter Name Type Required Description
queries array Pass at least one item for a business query. If omitted or an empty array is passed, empty data is returned.
Null allowed: False
Example: [{"qtype": "dql", "query": {"q": "M::`cpu`:(`usage_idle`)", "timeRange": [1785427200000, 1785430800000], "limit": 5}}]
How to obtain or enter: Construct query items by referring to the regular query and QueryHub examples; qtype determines the query type.
fieldTagDescNeeded boolean Default: false.
Null allowed: False
Example: false
How to obtain or enter: Pass true when you also need to read field or Tag descriptions.

Additional Parameter Notes

QueryHub is submitted only via POST JSON. Set queries[].qtype to queryhub, and pass datasourceId, mode, and the native or dql object with the same name in query. The API Key requires routine.defaultAccess and instance query permission for the current workspace. A synchronous batch can contain at most one QueryHub query. Individual item errors are in content.data[].query_error; on success, series and truncated are returned.

Query Notes


This endpoint supports both POST and GET, and both methods use the same JSON object parameter structure:

  • POST: The complete parameters are passed as an application/json request body;
  • GET: No HTTP entity body is used; pass it in the query string through body=<complete JSON object string>, and the client should URL-encode the body parameter;
  • The top level must be a JSON object; double JSON-encoded strings, arrays, null, numbers, or booleans are not accepted.

The response content.data[i].warnings[] may contain DQLDataAccessScopeRestricted:

  • details[0].metadata.namespace is fixed to logging in this release;
  • details[0].metadata.restriction=partial means only data from log indexes you have permission to access is returned;
  • details[0].metadata.restriction=all means none of the related log indexes have data access permission, and an empty result is returned;
  • The HTTP status code remains 200, and the warning coexists with existing GuanceDB/Kodo warnings.

The default values of optional parameters describe the behavior when the caller omits the parameter:

  • When query.timeRange is not passed, Studio passes time_range: [] downstream, does not add a fixed time window on the Studio side, and does not override the time range in the DQL statement. The current regular DQL Select main path falls back to querying the last 30 minutes through GuanceDB v1.52.0; this value is a downstream implementation detail and is not a unified OpenAPI default for all qtypes and all storage engines. PromQL queries require two time points to be explicitly provided. To ensure consistent behavior across versions and engines, explicitly pass two millisecond timestamps: [startTimeMs, endTimeMs].
  • query.limit, query.slimit, sorting, maximum point count, and query time limit are affected by the DQL statement, downstream service configuration, and storage engine, and there is no unified fixed OpenAPI default value; callers should pass them explicitly when they need stable boundaries.

Cross-workspace/cross-site query constraints:

  • All queries[*] in one request can point only to the same targetRegion; when querying multiple sites, split the request by site and merge the results on the client.
  • A non-empty workspaceUUIDs takes precedence over workspaceUUID; when workspaceUUIDs is an empty array or null, workspaceUUID is used as a fallback. Do not pass both fields at the same time. For queries in the current workspace, both can be omitted; when explicitly querying an authorized workspace, it is recommended to also pass the targetRegion to which that authorized workspace belongs.
  • When workspaceUUIDs=["*"], targetRegion can be specified; if it is not passed, authorized workspaces and the current workspace are queried on the current site. The compatible form workspaceUUID="*" remains supported and follows the same rules.
  • Target workspaces and targetRegion should be obtained through /api/v1/wksp_share/granted_ws_list. For a complete example, see OpenAPI Cross-Site Data Query.

  • Parameter Description

Parameter Name Type Required Default / Omission Behavior Description
queries array [] (returns empty data) Multi-command query; its content is a list of query objects; a business query should pass at least one query
fieldTagDescNeeded boolean false Whether field or tag description information is needed
  1. queries[*] Member Parameter Structure
Parameter Name Type Required Default / Omission Behavior Description
qtype string dql Query statement type
dql: indicates a DQL query statement;
promql: indicates a PromQL query statement. Example: dql.
query json Y - Required for a valid query; if missing or if query.q is empty, no valid downstream query is formed. Example: {"q":"M::`cpu`:(`usage_idle`)","timeRange":[1785427200000,1785430800000],"limit":5}.
query.q string Empty string (usually does not form a valid query) Query statement consistent with the qtype, such as a DQL or PromQL query statement. Example: M::`cpu`:(`usage_idle`). Copy the statement from the query tool, or construct it from the field names in the Measurement Schema/log Schema.
query.ignore_cache boolean false Whether to disable caching; false means caching is used. Example: false.
query.disable_streaming_aggregation boolean false Whether to disable streaming aggregation; explicitly passing true disables it, and explicitly passing false allows it. Example: false.
query.promqlType enum rangeQuery Takes effect when qtype=promql; valid values are instantQuery and rangeQuery. Example: rangeQuery.
query.highlight boolean false Whether to display highlighted data. Example: false.
query.timeRange array [] External time range; for DQL, if not passed, the window in the statement is not overridden, and the current regular Select main path falls back to the last 30 minutes through GuanceDB; for PromQL, two time points must be explicitly passed, and other engines may behave differently; the start and end times for DQL / PromQL must use the same unit (seconds, milliseconds, microseconds, or nanoseconds); mixing units returns HTTP 400 ft.TimeRangeUnitMismatch; pagination cursors remain independent. Example: [1785427200000,1785430800000]. Replace this with the two timestamps of the required query window at the same precision; Unix milliseconds are recommended.
query.disableMultipleField bool true Whether to enable single-column mode. Example: true.
query.showLabel bool false Whether to display the labels of the object. Example: false.
query.funcList array [] Aggregates and modifies DQL return values again; processed according to the selected aggregation function. Example: ["last"].
query.slimit integer Determined by DQL / downstream configuration Time series group size; valid only for metric queries. Example: 10.
query.soffset integer Value in DQL; no additional offset when DQL also does not set one Time series group offset; the current parser uses only positive external values to fill in an offset not set in DQL, and 0 does not clear an existing DQL value. Example: 10.
query.limit integer Determined by DQL / downstream configuration Page size. Example: 5.
query.offset integer Value in DQL; no additional offset when DQL also does not set one Pagination offset; the current parser uses only positive external values to fill in an offset not set in DQL, and 0 does not clear an existing DQL value. Example: 5.
query.orderby array Determined by DQL / query engine Sort list with the structure {fieldName: method}; measurement queries support only fieldName=time, and method can be desc or asc. Example: [{"time":"desc"}].
query.sorderby array Determined by DQL / query engine Sort list; column supports aggregation functions that return a single value, such as min, max, last, avg, p90, p95, and count
query.order_by array Determined by DQL / query engine Doris engine-compatible sort list with the structure [{"column": "field", "order": "DESC"}]. Example: [{"column":"time","order":"DESC"}].
query.sorder_by array Determined by DQL / query engine Doris engine-compatible time series sort list with the structure [{"column": "field", "order": "DESC"}]. Example: [{"column":"usage_idle","order":"DESC"}].
query.density string Determined by DQL / query engine Response point density; takes precedence over control parameters in the DQL statement. Example: medium.
query.interval number Determined by DQL / query engine Time slice interval; only accepts integers that can be converted to the Kodo int64 range and are not less than 1 ms; the unit is specified by interval_unit. Example: 60.
query.interval_unit string s Unit of interval; valid values are s and ms. Example: s.
query.align_time boolean false Whether to align time slices to the query engine time grid. Example: false.
query.tz string Asia/Shanghai Query time zone. Example: Asia/Shanghai.
query.search_after array No pagination marker set Deep pagination parameter; the next request should pass the search_after from the previous response. Example: [1785427200000,"cursor-example"]. For continuation pages, you must copy the array actually returned by the same query in the previous response.
query.maxPointCount integer Determined by DQL / query engine Maximum point count. Example: 360.
query.workspaceUUID string Current workspace UUID of a single authorizing workspace to query; * means query all authorized workspaces in targetRegion. Example: wksp_example.
query.workspaceUUIDs array Not set List of authorizing workspace UUIDs to query; when non-empty, takes precedence over query.workspaceUUID. The same list must belong to the same site; ["*"] means query all authorized workspaces in targetRegion. Do not pass both fields at the same time. Example: ["wksp_example"].
query.targetRegion string Current workspace queries imply the current site; wildcard defaults to the current site regionCode of the site to which the authorizing workspace belongs; obtain it from the regionCode in the same group as the target workspaceUUID in /wksp_share/granted_ws_list. It is recommended to pass it for explicit cross-site queries; when wildcarding and omitting it, the current site is used; the compatible form workspaceUUID="*" follows the same rules. Example: example-region.
query.output_format string Existing JSON response format When set to lineprotocol, the content of an individual query can use line protocol, while the outer response remains JSON. Example: lineprotocol.
query.cursor_time integer No cursor set Set to end_time on the first segmented query; afterward, pass the next_cursor_time from the response. Example: 1785430800000. Continuation pages use next_cursor_time from the response.
query.cursor_token string No token set When paginating, pass the next_cursor_token from the previous response; if not passed, data with the same timestamp may be skipped when paging. Example: cursor-example. Continuation pages use next_cursor_token from the response.
query.disable_sampling bool false Whether to disable sampling. Example: false.
query.disable_truncate bool false Whether to disable truncation of returned content; false means truncation is allowed. Example: false.
  1. Response Point Density density Parameter Values
Valid Value Description
lower Lower, 60 points
low Low, 180 points
medium Medium, 360 points
high High, 720 points
  • Note the precedence of the point density parameter; maximum density density[high] * interval takes precedence over density and the point density settings in DQL. maxPointCount can further limit the derived number of points.

  • Common Query Notes

  • Unrecovered Events Query

  • OpenAPI Cross-Site Data Query

Data visibility depends on the effective permissions of the API Key, workspace authorization, and data access rules.

  1. Request JSON Format Error

When the request body is not valid JSON, the endpoint returns HTTP 400 before entering query processing, and errorCode is the shared error code ft.RequestJsonFormatError. content.reason, content.line, and content.column indicate the JSON parsing reason, line number, and column number, respectively; the response does not echo the original request body.

{
  "code": 400,
  "content": {
    "reason": "Expecting property name enclosed in double quotes",
    "line": 22,
    "column": 17
  },
  "errorCode": "ft.RequestJsonFormatError",
  "message": "请求 JSON 格式错误",
  "success": false,
  "traceId": "TRACE-..."
}

QueryHub Request Fields

Parameter How to Enter
queries[].qtype Set to queryhub for a QueryHub query item.
queries[].uuid Optional client query identifier, for example demo-query; returned unchanged in the response.
queries[].query.datasourceId Obtain the effective data source ID from the External Data Source integration in the current workspace, for example orders.
queries[].query.mode Required; choose either native or dql, and fill in only the object with the same name as mode.
queries[].query.native For MySQL or PostgreSQL, you can fill in language=sql and statement, for example SELECT 1 AS value; a parameters array can also be provided.
queries[].query.dql QueryHub DQL query object. Fill in the dql statement, and optionally add dqlVersion (default queryhub/v1) and a parameters object.
queries[].query.expectedRevision Optional positive integer used to validate against the data source configuration revision known to the caller.

Request Examples

curl 'https://openapi.guance.com/api/v1/df/query_data_v1' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"queries":[{"qtype":"dql","query":{"q":"M::`cpu`:(`usage_idle`)","timeRange":[1785427200000,1785430800000],"limit":5}}]}'

QueryHub Native SQL Example

curl 'https://openapi.guance.com/api/v1/df/query_data_v1' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"queries":[{"qtype":"queryhub","uuid":"demo-query","query":{"datasourceId":"orders","mode":"native","native":{"language":"sql","statement":"SELECT 1 AS value"}}}]}'

Response

HTTP 200, application/json. Read results and errors by query item.

Field Type Description
content.data array<object> Batch results returned by the query. Parse by query item.
content.data[].series array<object> Data series. Can be empty when there is no data or the query item fails.
content.data[].series[].columns array<string> Column names of the series.
content.data[].series[].values array Result rows arranged in the order of columns.
content.data[].series[].name string Series name returned according to the engine and query type.
content.data[].series[].units array Units returned in the order of columns; elements can be strings or null. The field can be omitted.
content.data[].series[].tags object Grouping information that can be returned when grouped by tag.
content.data[].column_names array<string> Column names additionally provided by some engines.
content.data[].complete boolean Whether the engine reports the result as complete.
content.data[].is_running boolean Whether the query item is still running.
content.data[].search_after array Legacy segmented pagination cursor. Used only for continuation pages of the same query.
content.data[].next_cursor_time integer New cursor time. A negative value indicates that there are no more records.
content.data[].next_cursor_token string Token accompanying the new cursor; can be empty.
content.data[].warnings array<object> Query warnings. HTTP 200 may still be returned when some indexes are restricted.
content.data[].query_error object Error object for an individual query item; can appear together with HTTP 200.
content.data[].query_error.errorCode string Individual item error identifier.
content.data[].query_error.errorType integer Error type returned by the regular DQL query engine, provided according to the actual response.
content.data[].query_error.error string Text provided for some regular DQL errors.
content.declaration object or null Workspace declaration.
content.data[].query_status string QueryHub individual item status: success or failed.
content.data[].query_error.message string Error message for a QueryHub individual item.
content.data[].series[].columnTypes array<string> QueryHub column types, corresponding one-to-one with columns.
content.data[].uuid string or null Client identifier of the QueryHub query item.
content.data[].truncated boolean Whether the successful QueryHub result was truncated.
Response Header Type Description
Cache-Control string Responses from the QueryHub branch use no-store.
{
  "code": 200,
  "content": {
    "data": [
      {
        "column_names": [
          "time",
          "usage_idle"
        ],
        "complete": true,
        "is_running": false,
        "series": [
          {
            "columns": [
              "time",
              "usage_idle"
            ],
            "values": [
              [
                1785427260000,
                91.5
              ]
            ]
          }
        ]
      }
    ],
    "declaration": null
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

QueryHub Success Example

{"code": 200, "content": {"data": [{"uuid": "demo-query", "query_status": "success", "is_running": false, "truncated": false, "series": [{"columns": ["value"], "columnTypes": ["integer"], "values": [[1]]}]}], "declaration": null}, "errorCode": "", "message": "", "success": true, "traceId": "TRACE-EXAMPLE"}

QueryHub Individual Item Failure Under HTTP 200

{"code": 200, "content": {"data": [{"uuid": "demo-query", "query_status": "failed", "is_running": false, "series": [], "query_error": {"errorCode": "QueryHubForbidden", "message": "没有查询权限。"}}], "declaration": null}, "errorCode": "", "message": "", "success": true, "traceId": "TRACE-EXAMPLE"}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

For a QueryHub individual item failure, check query_error.errorCode. Unauthorized data sources, timeouts, or rejected queries can correspond to QueryHubForbidden, QueryHubQueryTimeout, or QueryHubQueryRejected. Individual item error identifiers do not include the forethought. prefix.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed Request parameters violate the field declaration The message indicates the invalid field or rule. Correct the request according to the corresponding parameter table.
400 ft.RequestJsonFormatError Request JSON syntax error Request JSON format error. content includes reason, line, and column. Fix the JSON syntax and retry.
400 ft.TimeRangeUnitMismatch The start and end times in timeRange use different units The start and end time units are inconsistent. Use timestamps with the same precision.
403 ft.ForbiddenQuery The API Key is not authorized to query the target data, or the target site rejects the cross-site query with a permission error No DQL query permission. Check the target workspace authorization and target site.
403 forethought.QueryHubForbidden The QueryHub request lacks the required query permission No query permission. Check the API Key and instance query permission.
400 ft.JsonFormatError The JSON top level or query item structure is invalid, or the request content is too deeply nested Partial JSON file format error. Check that the top level and the query in each query item are objects, and remove extra nesting.
406 ft.InvalidParameter interval or interval_unit does not meet the requirements Invalid parameter. Confirm that the unit is s/ms and can be converted to a positive integer number of milliseconds.
406 ft.DqlParseError The DQL query statement cannot be parsed Query statement parsing failed; may include detailed information. Validate the syntax in the query tool first.
406 ft.UnsupportMultiSiteQuery The batch query spans multiple sites Multi-site workspace queries are not supported. Submit separately for each site.
406 ft.workspaceUnauthorized An unauthorized workspace was explicitly requested The message indicates the unauthorized workspace. Obtain available identifiers again from the authorized workspace list.
406 ft.NotFoundWorkspaceAuthorizationCfg No corresponding authorization is found for the cross-site query Workspace authorization information was not found. Confirm the sharing configuration between the site and the workspace.
406 ft.OpenapiDqlLoggingWildcardIndexForbidden Index settings restrict all-index queries Explicitly specify a log index. Get the index name from the log index list.
406 ft.OpenapiDqlLoggingIndexLimitExceeded The number of log indexes exceeds the configured limit The message includes the number of indexes that can be queried at one time. Narrow the index scope.
503 ft.QueryServiceUnavailable The query service is temporarily unavailable The query service is temporarily unavailable; try again later. Retry with backoff according to content.retryable and the actual status.
400 forethought.QueryHubInvalidFields The QueryHub batch is invalid, or QueryHub is submitted with GET/URL body The message can be empty. Submit 1 to 20 query items using POST JSON.
422 forethought.QueryHubUseAsync A synchronous request contains multiple QueryHub queries The message can be empty. Use the asynchronous API.
503 forethought.QueryHubUnavailable The QueryHub feature is not enabled or the service is unavailable The query service or data source is temporarily unavailable. Check permissions, query functionality, and service status.

Feedback

Is this page helpful?