文档

SQL处理

URL

/v3/openapi/apps/$app_name/sql-search?format=json

  • $app_name:表示应用名(标准版是多应用版本类型,需要指定应用名访问,主要针对服务中的应用版本)。

  • 以上 URL 省略了请求Header参数及编码等因素。

  • 以上 URL 中省略了访问应用的 host 地址。

请求协议

HTTP

请求方式

POST

请求体

{
  "query": {
    "text" : "select count(id) from item_table",
    "dynamic_params" : []
  },
  "user_id" :"",
  "raw_query" : "",
  "format" : "json"
}

查询参数

查询参数具体拼接规则,详情请参见v3 API 签名机制文档。

参数

类型

必需

取值范围

默认值

描述

query.text

string

sql语句搜索主体,不能为空。

query.dynamic_params

string

动态参数。

user_id

string

用来标识发起当前搜索请求的终端用户。该值可以设置为下列值,优先级从高到低:1. 终端用户的长登录会员ID2. 终端用户的移动设备imei标识

raw_query

string

用于类目预测等算法训练使用,因此,建议所有查询都设置该参数;

format

string

只支持json

相应结果

  • 返回结果

参数

类型

描述

status

string

执行结果,OK为成功,FAIL为失败,请根据返回错误码进行排查

request_id

string

该条查询的记录id,主要用于排查问题使用

result

json

实际返回结果,包括查询耗时searchtime、引擎总结果数total、本次请求返回结果数num、本次查询最大返回结果数viewtotal、查询结果items、统计结果facet等信息

errors

list

错误码和错误内容,message代表错误信息;code 对应含义参考 错误码文档

  • searchtime:指引擎耗时,单位为秒。

  • numnum为本次查询请求实际返回的条目。

  • compute_cost:是一个只有一个map元素的数组,其中index_name表示应用ID,value表示本次查询消耗的LCU。

  • sql_result包含查询召回数据信息, column_name表示列名,column_type",列类型,data 每行数据。

Search示例

返回结果JSON

{
		"searchtime": 0.031811,
		"total": 84183,
		"compute_cost": [
			{
				"index_name": "110300582",
				"value": 8.939
			}
		],
	"num": 10,
	"sql_result": {
    "column_name":[
        "nid",
        "price",
        "brand",
        "size"
    ],
    "column_type":[
        "uint64",
        "double",
        "string",
        "double"
    ],
    "data":[
        [
            1,
            3599,
            "Huawei",
            5.9
        ],
        [
            2,
            4388,
            "Huawei",
            5.5
        ],
        [
            3,
            899,
            "Xiaomi",
            5
        ],
        [
            4,
            2999,
            "OPPO",
            5.5
        ],
        [
            5,
            1299,
            "Meizu",
            5.5
        ],
        [
            6,
            169,
            "Nokia",
            1.4
        ],
        [
            7,
            3599,
            "Apple",
            4.7
        ],
        [
            8,
            5998,
            "Apple",
            5.5
        ],
        [
            9,
            4298,
            "Apple",
            4.7
        ],
        [
            10,
            5688,
            "Samsung",
            5.6
        ]
    ]
},
	"request_id": "166927697116798130019226",
	"errors": [],
	"status": "OK"
}

错误返回

{
    "errors": [
        {
            "code": 1000,
            "message": "Server error."
        }
    ],
    "request_id": "167781933316779425502098",
    "result": {
        "compute_cost": [
            {
                "index_name": "120134275",
                "value": 0.2286
            }
        ],
        "items": {},
        "num": 0,
        "searchtime": 0.010344
    },
    "status": "OK"
}

  • 说明:status为FAIL表示既有error又无结果返回;但可能会出现既有error,又会有结果返回,此时status就为OK.

  • 本页导读 (0)
文档反馈