Skip to content

Commit 6ae1894

Browse files
committed
add multi_termvectors
1 parent 559a808 commit 6ae1894

File tree

3 files changed

+161
-2
lines changed

3 files changed

+161
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ npm run docs:dev
916916
- :heavy_check_mark: 批量 API [:link:](https://elasticsearch.bookhub.tech/rest_apis/document_apis/bulk)
917917
- :heavy_check_mark: 重索引 API [:link:](https://elasticsearch.bookhub.tech/rest_apis/document_apis/reindex)
918918
- :heavy_check_mark: 词向量 API [:link:](https://elasticsearch.bookhub.tech/rest_apis/document_apis/termvectors)
919-
- Multi term vectors
919+
- :heavy_check_mark: 多词向量 API [:link:](https://elasticsearch.bookhub.tech/rest_apis/document_apis/multi_termvectors)
920920
- ?refresh
921921
- Optimistic concurrency control
922922
- Enrich APIs
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# 多词向量 API
2+
3+
只需一次请求即可检索多个词(term)向量。
4+
5+
```bash
6+
POST /_mtermvectors
7+
{
8+
"docs": [
9+
{
10+
"_index": "my-index-000001",
11+
"_id": "2",
12+
"term_statistics": true
13+
},
14+
{
15+
"_index": "my-index-000001",
16+
"_id": "1",
17+
"fields": [
18+
"message"
19+
]
20+
}
21+
]
22+
}
23+
```
24+
25+
## 请求
26+
27+
`POST /_mtermvectors`
28+
29+
`POST /<index>/_mtermvectors`
30+
31+
## 前置条件
32+
33+
- 如果启用了 Elasticsearch 安全功能,则必须拥有目标索引或索引别名的 `read` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)
34+
35+
## 描述
36+
37+
你可以通过索引和 ID 指定现有文档,也可以在请求正文中提供人工文档。你可以在请求体或请求 URI 中指定索引。
38+
39+
响应包含一个 `docs` 数组,其中包含所有获取的词向量。每个元素都有[词向量](/rest_apis/document_apis/termvectors) API 提供的结构。
40+
41+
有关可包含在响应中的信息的更多信息,参阅[词向量](/rest_apis/document_apis/termvectors) API。
42+
43+
## 路径参数
44+
45+
- `<index>`
46+
47+
(可选,字符串)包含文件的索引名称。
48+
49+
## 查询参数
50+
51+
- `fields`
52+
53+
(可选,字符串) 用逗号分隔的字段列表或通配符表达式,这些字段将包含在统计信息中。
54+
55+
除非在 `completion_fields``fielddata_fields` 参数中提供了特定字段列表,否则将作为默认列表使用。
56+
57+
- `field_statistics`
58+
59+
(可选,布尔值) 如果为 `true`,响应将包括文档计数、文档频率总和以及词总频率总和。默认为 `true`
60+
61+
- `<offsets>`
62+
63+
(可选,布尔值) 如果为 `true`,则响应包括词偏移。默认为 `true`
64+
65+
- `payloads`
66+
67+
(可选,布尔值) 如果为 `true`,则响应包括词有效载荷。默认为 `true`
68+
69+
- `positions`
70+
71+
(可选,布尔值) 如果为 `true`,则响应包括词位置。默认为 `true`
72+
73+
- `preference`
74+
75+
(可选,字符串) 指定应在哪个节点或分片上执行操作。默认为随机。
76+
77+
- `routing`
78+
79+
(可选,字符串) 用于将操作路由到特定分区的自定义值。
80+
81+
- `realtime`
82+
83+
(可选,布尔值) 如果为 `true`,则表示请求是实时的,而不是近实时的。默认为 `true`。参阅[实时](/docs/rest_apis/document_apis/get#实时)
84+
85+
- `term_statistics`
86+
87+
(可选,布尔值)如果为 `true`,则响应包括词频和文档频率。默认为 `false`
88+
89+
- `version`
90+
91+
(可选,布尔值) 如果为 `true`,则返回作为命中一部分的文档版本。
92+
93+
- `version_type`
94+
95+
(可选,枚举值) 特定版本类型:`external``external_gte`
96+
97+
### 示例
98+
99+
如果在请求 URI 中指定索引,则无需为请求体中的每个文档指定索引:
100+
101+
```bash
102+
POST /my-index-000001/_mtermvectors
103+
{
104+
"docs": [
105+
{
106+
"_id": "2",
107+
"fields": [
108+
"message"
109+
],
110+
"term_statistics": true
111+
},
112+
{
113+
"_id": "1"
114+
}
115+
]
116+
}
117+
```
118+
119+
如果请求的所有文件都在同一索引中,且参数相同,则可使用以下简化语法:
120+
121+
```bash
122+
POST /my-index-000001/_mtermvectors
123+
{
124+
"ids": [ "1", "2" ],
125+
"parameters": {
126+
"fields": [
127+
"message"
128+
],
129+
"term_statistics": true
130+
}
131+
}
132+
```
133+
134+
### 人工文档
135+
136+
你还可以使用 `mtermvectors` 为请求体中提供的人工文档生成词向量。使用的映射由指定的 `_index` 决定。
137+
138+
```bash
139+
POST /_mtermvectors
140+
{
141+
"docs": [
142+
{
143+
"_index": "my-index-000001",
144+
"doc" : {
145+
"message" : "test test test"
146+
}
147+
},
148+
{
149+
"_index": "my-index-000001",
150+
"doc" : {
151+
"message" : "Another test ..."
152+
}
153+
}
154+
]
155+
}
156+
```
157+
158+
> [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html)

sidebars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ const sidebars = {
166166
'rest_apis/document_apis/multi_get',
167167
'rest_apis/document_apis/bulk',
168168
'rest_apis/document_apis/reindex',
169-
'rest_apis/document_apis/termvectors'
169+
'rest_apis/document_apis/termvectors',
170+
'rest_apis/document_apis/multi_termvectors'
170171
]
171172
},
172173
{

0 commit comments

Comments
 (0)