原英文版地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/docs-multi-termvectors.html, 原文档版权归 www.elastic.co 所有
本地英文版地址: ../en/docs-multi-termvectors.html

Multi term vectors APIedit

Retrieves multiple term vectors with a single request.

POST /_mtermvectors
{
   "docs": [
      {
         "_index": "twitter",
         "_id": "2",
         "term_statistics": true
      },
      {
         "_index": "twitter",
         "_id": "1",
         "fields": [
            "message"
         ]
      }
   ]
}

Requestedit

POST /_mtermvectors

POST /<index>/_mtermvectors

Descriptionedit

You can specify existing documents by index and ID or provide artificial documents in the body of the request. The index can be specified the body of the request or in the request URI.

The response contains a docs array with all the fetched termvectors. Each element has the structure provided by the termvectors API.

See the termvectors API for more information about the information that can be included in the response.

Path parametersedit

<index>
(Optional, string) Name of the index that contains the documents.

Query parametersedit

fields

(Optional, string) Comma-separated list or wildcard expressions of fields to include in the statistics.

Used as the default list unless a specific field list is provided in the completion_fields or fielddata_fields parameters.

field_statistics
(Optional, boolean) If true, the response includes the document count, sum of document frequencies, and sum of total term frequencies. Defaults to true.
<offsets>
(Optional, boolean) If true, the response includes term offsets. Defaults to true.
payloads
(Optional, boolean) If true, the response includes term payloads. Defaults to true.
positions
(Optional, boolean) If true, the response includes term positions. Defaults to true.
preference
(Optional, string) Specifies the node or shard the operation should be performed on. Random by default.
routing
(Optional, string) Target the specified primary shard.
realtime
(Optional, boolean) If true, the request is real-time as opposed to near-real-time. Defaults to true. See Realtime.
term_statistics
(Optional, boolean) If true, the response includes term frequency and document frequency. Defaults to false.
version
(Optional, boolean) If true, returns the document version as part of a hit.
version_type
(Optional, enum) Specific version type: internal, external, external_gte.

Examplesedit

If you specify an index in the request URI, the index does not need to be specified for each documents in the request body:

POST /twitter/_mtermvectors
{
   "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:

POST /twitter/_mtermvectors
{
    "ids" : ["1", "2"],
    "parameters": {
    	"fields": [
         	"message"
      	],
      	"term_statistics": true
    }
}

Artificial documentsedit

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.

POST /_mtermvectors
{
   "docs": [
      {
         "_index": "twitter",
         "doc" : {
            "user" : "John Doe",
            "message" : "twitter test test test"
         }
      },
      {
         "_index": "twitter",
         "doc" : {
           "user" : "Jane Doe",
           "message" : "Another twitter test ..."
         }
      }
   ]
}