推荐字段取值 TermsEnum
更新时间:2025-10-13
描述
推荐字段取值
接口限制
- 入参不支持timeout字段,BLS会一直查询至到超时报错
- 返回结果中不包括_shards字段,由于不会超时终止,因此complete字段都是true
请求
- 请求语法
Text
1POST /<name>/_terms_enum HTTP/1.1
2Host: <Endpoint>
3Authorization: <Authorization String>
- 请求头域
除公共请求头域外,无其它特殊头域。
- 请求参数
| 参数名称 | 类型 | 是否必须 | 参数位置 | 描述 |
|---|---|---|---|---|
| name | String | Yes | Path | 索引名称,不支持模糊匹配 |
| field | String | Yes | RequestBody | 索引字段名称,不支持模糊匹配 |
| string | String | No | RequestBody | 用于前缀匹配的字符串。比如 "ki" 会匹配以 ki 开头的 terms |
| size | Int | No | RequestBody | 返回多少个terms 默认 10 |
| index_filter | Query | No | RequestBody | 限制从哪些文档里枚举 terms,语法同普通query DSL |
注:elasticsearch的查询语法参考官网
成功响应
- 响应头域
除公共响应头域外,无其它特殊头域。
- 响应参数
| 字段 | 类型 | 描述 |
|---|---|---|
| terms | List<String> | 返回匹配到的term值数组 |
异常响应
- 响应头域
除公共响应头域外,无其它特殊头域。
- 响应参数
| 字段 | 类型 | 描述 |
|---|---|---|
| error | Error | 错误原因 |
| status | Int | http状态码,比如:500 |
上表中的 Error 对象的元素结构如下:
| 字段 | 类型 | 描述 |
|---|---|---|
| root_cause | List<Error> | 根原因 |
| type | String | 错误类型 |
| reason | String | 错误原因 |
示例
- 请求示例
Text
1POST /my-index/_terms_enum HTTP/1.1
2Host: bls-log.bj.baidubce.com
3Authorization:bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
4Content-Type: application/json; charset=utf-8
5{
6 // 必填 索引字段名称
7 "field": "user",
8 // 可选 用于前缀匹配的字符串。比如 "ki" 会匹配以 ki 开头的 terms。
9 "string": "ki",
10 // 可选,返回多少个terms 默认 10
11 "size": 5,
12 // 限制从哪些文档里枚举 terms,语法同普通query DSL。
13 "index_filter": {
14 // 存在某个字段
15 "exists": {
16 // 只在存在response这个字段的日志中查询term
17 "field": "response"
18 }
19 }
20}
- 响应示例
Text
1HTTP/1.1 204
2Content-Type: application/json; charset=utf-8
3X-Bce-Request-Id: 2eeba101-4cc7-4cfe-b5ac-a3be8d060e33
4Date: Fri, 10 Apr 2020 04:42:37 GMT
5
6// 成功示例
7{
8 // 返回匹配到的term值数组。
9 "terms": [
10 "kimchy",
11 "kirk",
12 "kitten"
13 ],
14 // true 表示结果完整,false 表示可能有更多terms被截断
15 "complete": true
16}
17
18// 异常实例
19{
20 "error": {
21 "root_cause": [
22 {
23 "type": "illegal_argument_exception",
24 "reason": "illegal_argument_exception",
25 }
26 ],
27 "type": "illegal_argument_exception",
28 "reason": "illegal_argument_exception"
29 },
30 "status": 500
31}
