Elasticsearch专题精讲—— REST APIs —— Document APIs —— Multi term vectors API
REST APIs —— Document APIs —— Multi term vectors API
https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-multi-termvectors.html
Retrieves multiple term vectors with a single request.
检索具有单个请求的多个 term(词项)向量。
curl -X POST "localhost:9200/_mtermvectors?pretty" -H 'Content-Type: application/json' -d' { "docs": [ { "_index": "my-index-000001", "_id": "2", "term_statistics": true }, { "_index": "my-index-000001", "_id": "1", "fields": [ "message" ] } ] }'
1、Request(请求)
https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-multi-termvectors.html#docs-multi-termvectors-api-request
POST /_mtermvectors POST /< index>/_mtermvectors
2、Prerequisites(先决条件)
https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-multi-termvectors.html#docs-multi-termvectors-api-prereqs
If the Elasticsearch security features are enabled, you must have the read index privilege for the target index or index alias.
如果启用了 Elasticsearch 安全特性,则必须拥有目标索引或索引别名的读索引特权。
3、Description(描述)
https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-multi-termvectors.html#docs-multi-termvectors-api-desc
You can specify existing documents by index and ID or provide artificial documents in the body of the request. You can specify the index in the request body or request URI.
您可以通过索引和 ID 指定现有文档,或者在请求体中提供人工文档。可以在请求体或请求 URI 中指定索引。
The response contains a docs array with all the fetched termvectors. Each element has the structure provided by the termvectors API.
响应包含一个 docs 数组,其中包含所有获取的术语向量。每个元素都有 termvectors(https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-termvectors.html) API 提供的结构。
See the termvectors API for more information about the information that can be included in the response.
有关可以包含在响应中的信息的更多信息,请参见 term vectors API(向量 API)(https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-termvectors.html)。
4、Example(例子)
https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-multi-termvectors.html#docs-multi-termvectors-api-example
If you specify an index in the request URI, the index does not need to be specified for each documents in the request body:
如果在请求URI中指定了索引,那么在请求正文中的每个文档都不需要指定索引。
curl -X POST "localhost:9200/my-index-000001/_mtermvectors?pretty" -H 'Content-Type: application/json' -d' { "docs": [ { "_id": "2", "fields": [ "message" ], "term_statistics": true }, { "_id": "1" } ] }'
If all requested documents are in same index and the parameters are the same, you can use the following simplified syntax:
如果所有请求的文档都在同一个索引中,并且参数相同,则可以使用以下简化语法:
curl -X POST "localhost:9200/my-index-000001/_mtermvectors?pretty" -H 'Content-Type: application/json' -d' { "ids": [ "1", "2" ], "parameters": { "fields": [ "message" ], "term_statistics": true } }'
5、Artificial documents(人工文档)
https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-multi-termvectors.html#docs-multi-termvectors-artificial-doc
You can also use mtermvectors to generate term vectors for artificial documents provided in the body of the request. The mapping used is determined by the specified _index.
您还可以使用 mtermvectors 为请求正文中提供的人工文档生成 term vectors(词项向量)。使用的映射由指定的 _index 确定。
curl -X POST "localhost:9200/_mtermvectors?pretty" -H 'Content-Type: application/json' -d' { "docs": [ { "_index": "my-index-000001", "doc" : { "message" : "test test test" } }, { "_index": "my-index-000001", "doc" : { "message" : "Another test ..." } } ] }'