问题查数¶
本接口在 v25.9 版本中引入
请求方式¶
Request Method: POST
Request URL: /openapi/v1/workspaces/{workspaceId}/data/question/
Request Header:
Authorization: "{连接密钥}"
请求参数¶
{
"memberUid": "{memberUid}",
"text": "{text}",
"skip_pre_rule": false
}
请求参数说明¶
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| workspaceId | string | 是 | 用户工作区的 id |
| 连接密钥 | string | 是 | API密钥 |
| memberUid | string | 是 | 工作区中成员的 uid |
| text | string | 是 | 成员提的问题,比如“今年GMV” |
| skip_pre_rule | boolean | 否 | 是否跳过分词前规则,默认为 false(不跳过) |
返回结果¶
返回结果的 data 内包含如下字段:
| 参数 | 类型 | 说明 |
|---|---|---|
| url | string | 该问题对应的网页端链接 |
| type | string | 该问题对应回答类型,目前包含 metric 和 image |
| data | dict | 该问题对应回答数据 |
| tokens | list | 该问题的分词结果 |
| data.image | string | image 类型回答,对应图表卡片的 base64 编码 |
| data.metrics.N.name | string | metric类型回答,查询的数据指标显示名 |
| data.metrics.N.content | string | metric类型回答,查询的数据指标显示值 |
| data.metrics.N.value | float | metric类型回答,查询的数据指标实际值 |
| explanations | list | 该问题对应的解析解释 |
数字卡片类问题,类型为 metric,回答数据内 metrics 字段包含主要数据
{
"errcode": 200,
"errmsg": "success",
"data": {
"url": "https://datarc.cn/#/discover?key=question&projectId=1",
"type": "metric",
"data": {
"metrics": [
{
"name": "营业额",
"content": "29.3亿",
"value": "2930123456.7"
}
]
},
"explanations": []
}
}
图表卡片类问题,类型为 image,会返回 image 字段,包含了图片的 base64 信息
{
"errcode": 200,
"errmsg": "success",
"data": {
"url": "https://datarc.cn/#/discover?key=question&projectId=1",
"type": "image",
"data": {
"image": "iVBORw0KGgoAAAANSUhEUgAAAZAAAA..."
},
"explanations": []
}
}
不支持的卡片,类型为 unsupported
{
"errcode": 200,
"errmsg": "success",
"data": {
"url": "https://datarc.cn/#/discover?key=question&projectId=1",
"type": "unsupported",
"data": {},
"explanations": []
}
}
explanations 字段为对于问题的解释,explanations 字段主要数据
| 参数 | 类型 | 说明 |
|---|---|---|
| explanations.N.filters | list | 维度相关的过滤条件 |
| explanations.N.dateFilters | list | 日期相关的过滤条件 |
| explanations.N.dimensions | list | 维度 |
| explanations.N.measures | list | 指标 |
| explanations.N.keywords | list | 增长、变化、占比等关键词 |
| explanations.N.order | list | 排序 |
| explanations.N.limit | float | 数量限制 |
| explanations.N.having | list | 指标过滤条件 |
| explanations.N.proportion | list | 占比问法中,分子分母共有过滤条件 |
| explanations.N.model | string | 所选模型 |
| explanations.N.sql | string | sql 语句 |
| explanations.N.params | object | sql 语句参数 |
explanations.N.dateFilters 结构
[
[
{
"word": "日期",
"prop": "t1"
},
{
"word": "今年",
"prop": "dateRela_* * 1_12 */* 1_31"
},
{
"word": "2018-01-01 至 02-01",
"prop": "dateRange_2018010120180201",
"start": "2018-01-01",
"end": "2018-02-01",
"onlyText": true
}
]
]
explanations.N.order 结构
[
{
"tokens": [
{
"prop": "m1",
"word": "营业额"
},
{
"word": "降序",
"prop": "order_desc"
}
],
"customSort": false
}
]
explanations.N.proportion 结构
[
{
"text": "占比分子计算公式/占比分母计算公式"
}
]
- 假如无法查的数据,会返回 400 错误
{
"errcode": 400,
"errmsg": "用户问题无法搜索出有效结果"
}
// 无法查询表格类型
{
"errcode": 400,
"errmsg": "数据查询结果为表格"
}