系统提供了丰富的搜索语法以满足用户各种场景下的搜索需求。
URL
sql?query=SELECT brand, COUNT(*) FROM phone GROUP BY (brand)&&kvpair=trace:INFO;formatType:json
以上 URL 省略了请求Header参数及编码等因素。
以上 URL 中省略了访问应用的 host 地址。
以上URL 中拼接的所有查询参数,请查看下方“查询参数”的参数定义、使用方式及样例。
请求协议
HTTP
请求方式
GET
支持格式
JSON
签名机制
可用以下方法计算签名(authorization)
参数 | 类型 | 描述 |
accessUserName | String | 用户名,可在实例详情页>网络信息查看 |
accessPassWord | String | 密码,可在实例详情页>网络信息修改 |
import com.aliyun.darabonba.encode.Encoder;
import com.aliyun.darabonbastring.Client;
public class GenerateAuthorization {
public static void main(String[] args) throws Exception {
String accessUserName = "username";
String accessPassWord = "password";
String realmStr = "" + accessUserName + ":" + accessPassWord + "";
String authorization = Encoder.base64EncodeToString(Client.toBytes(realmStr, "UTF-8"));
System.out.println(authorization);
}
}
authorization正确返回格式
cm9vdDp******mdhbA==
注意:使用HTTP请求设置authorization参数是需加上Basic前缀
示例:
authorization: Basic cm9vdDp******mdhbA==
查询参数
参数 | 类型 | 必须 | 描述 |
query子句 | String | 是 | 请参考文档:query子句 |
kvpairs子句 | String | 否 | 请参考文档:kvpair子句 |
查询参数用法
query:query子句主要是拼写完整的sql语句。
返回参数
参数 | 类型 | 描述 |
total_time | String | 该条查询的记录id,主要用于排查问题使用 |
covered_percent | 覆盖率 | |
row_count | int |
curl示例
curl --location --request GET 'http://ha-cn-*******.public.ha.aliyuncs.com/query?sql=query=select * from index_hdf%26%26kvpair=trace:INFO;format:full_json' \
--header 'authorization: Basic ******************' \
--header 'host: ha-cn-*******.public.ha.aliyuncs.com'
说明
示例中的endpoint是公网访问的域名,详情可参考网络信息
Search示例
正常返回
{
"total_time": 4.557,
"covered_percent": 1.0,
"row_count": 1,
"format_type": "full_json",
"search_info": {},
"trace": [],
"sql_result": {
"data": [
[
1
]
],
"column_name": [
"id"
],
"column_type": [
"int64"
]
},
"error_info": {
"ErrorCode": 0,
"Error": "ERROR_NONE",
"Message": ""
}
}
错误返回
{
"total_time": 15.96,
"covered_percent": 0.0,
"row_count": 0,
"format_type": "full_json",
"search_info": {},
"trace": [],
"sql_result": {
"data": [],
"column_name": [],
"column_type": []
},
"error_info": {
"ErrorCode": 8010,
"Error": "call sql plan service failed.",
"Message": "failed to get sql plan, error message is [IQUAN_EC_INTERNAL_ERROR] internal error : SQL validation failed. From line 1, column 15 to line 1, column 23: Object 'index_hdf' not found\nFrom line 1, column 15 to line 1, column 23: Object 'index_hdf' not found\norg.apache.flink.table.api.ValidationException: SQL validation failed. From line 1, column 15 to line 1, column 23: Object 'index_hdf' not found\n\tat org.apache.flink.table.planner.calcite.FlinkPlannerImpl.org$apache$flink$table$planner$calcite$FlinkPlannerImpl$$validate(FlinkPlannerImpl.scala:149)\n\tat org.apache.flink.table.planner.calcite.FlinkPlannerImpl.validate(FlinkPlannerImpl.scala:108)\n\tat org.apache.flink.table.planner.delegation.ParserImpl.validate(ParserImpl.java:91)\n\tat com.taobao.search.iquan.core.api.impl.SqlQueryableImpl$SqlWorkFlow.validateSql(SqlQueryableImpl.java:646)\n\tat com.taobao.search.iquan.core.api.impl.SqlQueryableImpl$SqlWorkFlow.process(SqlQueryableImpl.java:392)\n\tat com.taobao.search.iquan.core.api.impl.SqlQueryableImpl.select(SqlQueryableImpl.java:134)\n\tat com.taobao.search.iquan.client.common.service.SqlQueryService.sqlQuery(SqlQueryService.java:89)\n\tat com.taobao.search.iquan.client.IquanClient.sqlQuery(IquanClient.java:79)\nCaused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 15 to line 1, column 23: Object 'index_hdf' not found\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\n\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\n\tat java.lang.reflect.Constructor.newInstance(Constructor.java:422)\n\tat org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:467)\n\tat org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:883)\n\tat org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:868)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:5032)\n\tat org.apache.calcite.sql.validate.IdentifierNamespace.resolveImpl(IdentifierNamespace.java:179)\n\tat org.apache.calcite.sql.validate.IdentifierNamespace.validateImpl(IdentifierNamespace.java:184)\n\tat org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1067)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1041)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3202)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3187)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3450)\n\tat org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)\n\tat org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1067)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1041)\n\tat org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:232)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1016)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:724)\n\tat org.apache.flink.table.planner.calcite.FlinkPlannerImpl.org$apache$flink$table$planner$calcite$FlinkPlannerImpl$$validate(FlinkPlannerImpl.scala:144)\n\t... 7 more\nCaused by: org.apache.calcite.sql.validate.SqlValidatorException: Object 'index_hdf' not found\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\n\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\n\tat java.lang.reflect.Constructor.newInstance(Constructor.java:422)\n\tat org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:467)\n\tat org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:560)\n\t... 26 more\n"
}
}
注意事项
查询query长度超过30K,请使用 RESTFUL API搜索处理
文档内容是否对您有帮助?