Multi term vectors API
Multi term vectors API
Retrieves multiple term vectors with a single request.
resp = client.mtermvectors(
docs=[
{
"_index": "my-index-000001",
"_id": "2",
"term_statistics": True
},
{
"_index": "my-index-000001",
"_id": "1",
"fields": [
"message"
]
}
],
)
print(resp)
response = client.mtermvectors(
body: {
docs: [
{
_index: 'my-index-000001',
_id: '2',
term_statistics: true
},
{
_index: 'my-index-000001',
_id: '1',
fields: [
'message'
]
}
]
}
)
puts response
const response = await client.mtermvectors({
docs: [
{
_index: "my-index-000001",
_id: "2",
term_statistics: true,
},
{
_index: "my-index-000001",
_id: "1",
fields: ["message"],
},
],
});
console.log(response);
POST /_mtermvectors
{
"docs": [
{
"_index": "my-index-000001",
"_id": "2",
"term_statistics": true
},
{
"_index": "my-index-000001",
"_id": "1",
"fields": [
"message"
]
}
]
}
Request
POST /_mtermvectors
POST /<index>/_mtermvectors
Prerequisites
- If the Elasticsearch security features are enabled, you must have the
read
index privilege for the target index or index alias.
Description
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.
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 parameters
<index>
(Optional, string) Name of the index that contains the documents.
Query parameters
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) Custom value used to route operations to a specific 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: external
, external_gte
.
Examples
If you specify an index in the request URI, the index does not need to be specified for each documents in the request body:
resp = client.mtermvectors(
index="my-index-000001",
docs=[
{
"_id": "2",
"fields": [
"message"
],
"term_statistics": True
},
{
"_id": "1"
}
],
)
print(resp)
response = client.mtermvectors(
index: 'my-index-000001',
body: {
docs: [
{
_id: '2',
fields: [
'message'
],
term_statistics: true
},
{
_id: '1'
}
]
}
)
puts response
const response = await client.mtermvectors({
index: "my-index-000001",
docs: [
{
_id: "2",
fields: ["message"],
term_statistics: true,
},
{
_id: "1",
},
],
});
console.log(response);
POST /my-index-000001/_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:
resp = client.mtermvectors(
index="my-index-000001",
ids=[
"1",
"2"
],
parameters={
"fields": [
"message"
],
"term_statistics": True
},
)
print(resp)
response = client.mtermvectors(
index: 'my-index-000001',
body: {
ids: [
'1',
'2'
],
parameters: {
fields: [
'message'
],
term_statistics: true
}
}
)
puts response
const response = await client.mtermvectors({
index: "my-index-000001",
ids: ["1", "2"],
parameters: {
fields: ["message"],
term_statistics: true,
},
});
console.log(response);
POST /my-index-000001/_mtermvectors
{
"ids": [ "1", "2" ],
"parameters": {
"fields": [
"message"
],
"term_statistics": true
}
}
Artificial documents
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
.
resp = client.mtermvectors(
docs=[
{
"_index": "my-index-000001",
"doc": {
"message": "test test test"
}
},
{
"_index": "my-index-000001",
"doc": {
"message": "Another test ..."
}
}
],
)
print(resp)
response = client.mtermvectors(
body: {
docs: [
{
_index: 'my-index-000001',
doc: {
message: 'test test test'
}
},
{
_index: 'my-index-000001',
doc: {
message: 'Another test ...'
}
}
]
}
)
puts response
const response = await client.mtermvectors({
docs: [
{
_index: "my-index-000001",
doc: {
message: "test test test",
},
},
{
_index: "my-index-000001",
doc: {
message: "Another test ...",
},
},
],
});
console.log(response);
POST /_mtermvectors
{
"docs": [
{
"_index": "my-index-000001",
"doc" : {
"message" : "test test test"
}
},
{
"_index": "my-index-000001",
"doc" : {
"message" : "Another test ..."
}
}
]
}