Multi Term Vectors API
_mtermvectors API는 하나의 요청으로 여러 문서에 대한 텀 벡터 정보를 검색해요. 텀 벡터는 문서 안의 텀(단어)에 대한 상세 정보를 제공하며, 여기에는 텀 빈도, 위치, 오프셋, 페이로드가 포함돼요. 이는 관련성 점수 계산, 하이라이팅, 유사도 계산 같은 애플리케이션에 유용해요. 자세한 내용은 Term vector parameter를 참고하세요.
출처: OpenSearch 문서
본문
엔드포인트 (Endpoints)
GET /_mtermvectors
POST /_mtermvectors
GET /{index}/_mtermvectors
POST /{index}/_mtermvectors
경로 매개변수 (Path parameters)
다음 표는 사용할 수 있는 경로 매개변수를 나열한 것이에요. 모든 경로 매개변수는 선택 사항이에요.
| Parameter | Data type | Description | | index | String | The name of the index that contains the document. |
쿼리 매개변수 (Query parameters)
다음 표는 사용할 수 있는 쿼리 매개변수를 나열한 것이에요. 모든 쿼리 매개변수는 선택 사항이에요.
| Parameter | Data type | Description | | field_statistics | Boolean | If true, the response includes the document count, sum of document frequencies, and sum of total term frequencies. (Default: true) | | fields | List or String | A comma-separated list or a wildcard expression specifying the 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. | | ids | List | A comma-separated list of documents IDs. You must provide either the docs field in the request body or specify ids as a query parameter or in the request body. | | offsets | Boolean | If true, the response includes term offsets. (Default: true) | | payloads | Boolean | If true, the response includes term payloads. (Default: true) | | positions | Boolean | If true, the response includes term positions. (Default: true) | | preference | String | Specifies the node or shard on which the operation should be performed. See preference query parameter for a list of available options. By default the requests are routed randomly to available shard copies (primary or replica), with no guarantee of consistency across repeated queries. | | realtime | Boolean | If true, the request is real time as opposed to near real time. (Default: true) | | routing | List or String | A custom value used to route operations to a specific shard. | | term_statistics | Boolean | If true, the response includes term frequency and document frequency. (Default: false) | | version | Integer | If true, returns the document version as part of a hit. | | version_type | String | The specific version type. Valid values are: - external: The version number must be greater than the current version. - external_gte: The version number must be greater than or equal to the current version. - internal: The version number is managed internally by OpenSearch. |
요청 본문 필드 (Request body fields)
다음 표는 요청 본문에서 지정할 수 있는 필드를 나열한 것이에요.
| Field | Data type | Description | | docs | Array | An array of document specifications. | | ids | Array of strings | A list of document IDs to retrieve. Use only when all documents share the same index specified in the request path or query. | | fields | Array of strings | A list of field names for which to return term vectors. | | offsets | Boolean | If true, the response includes character offsets for each term. (Default: true) | | payloads | Boolean | If true, the response includes payloads for each term. (Default: true) | | positions | Boolean | If true, the response includes token positions. (Default: true) | | field_statistics | Boolean | If true, the response includes statistics such as document count, sum of document frequencies, and sum of total term frequencies. (Default: true) | | term_statistics | Boolean | If true, the response includes term frequency and document frequency. (Default: false) | | routing | String | A custom routing value used to identify the shard. Required if custom routing was used during indexing. | | version | Integer | The specific version of the document to retrieve. | | version_type | String | The type of versioning to use. Valid values: internal, external, external_gte. | | filter | Object | Filters tokens returned in the response (for example, by frequency or position). For supported fields, see Filtering terms. | | per_field_analyzer | Object | Specifies a custom analyzer to use per field. Format: { "field_name": "analyzer_name" }. |
텀 필터링 (Filtering terms)
요청 본문의 filter 객체를 사용하면 텀 벡터 응답에 포함할 토큰을 필터링할 수 있어요. filter 객체는 다음 필드를 지원해요.
| Field | Data type | Description | | max_num_terms | Integer | The maximum number of terms to return. | | min_term_freq | Integer | The minimum term frequency in the document required for a term to be included. | | max_term_freq | Integer | The maximum term frequency in the document required for a term to be included. | | min_doc_freq | Integer | The minimum document frequency across the index required for a term to be included. | | max_doc_freq | Integer | The maximum document frequency across the index required for a term to be included. | | min_word_length | Integer | The minimum length of the term to be included. | | max_word_length | Integer | The maximum length of the term to be included. |
예제 요청 (Example requests)
텀 벡터를 활성화한 인덱스를 만들어요.
PUT /my-index
{
"mappings": {
"properties": {
"text": {
"type": "text",
"term_vector": "with_positions_offsets_payloads"
}
}
}
}
첫 번째 문서를 인덱싱해요.
POST /my-index/_doc/1
{
"text": "OpenSearch is a search engine."
}
response = client.index(
index = "my-index",
id = "1",
body = {
"text": "OpenSearch is a search engine."
}
)
두 번째 문서를 인덱싱해요.
POST /my-index/_doc/2
{
"text": "OpenSearch provides powerful features."
}
response = client.index(
index = "my-index",
id = "2",
body = {
"text": "OpenSearch provides powerful features."
}
)
예제 요청 (Example request)
여러 문서에 대한 텀 벡터를 가져와요.
POST /_mtermvectors
{
"docs": [
{
"_index": "my-index",
"_id": "1",
"fields": [
"text"
]
},
{
"_index": "my-index",
"_id": "2",
"fields": [
"text"
]
}
]
}
response = client.mtermvectors(
body = {
"docs": [
{
"_index": "my-index",
"_id": "1",
"fields": [
"text"
]
},
{
"_index": "my-index",
"_id": "2",
"fields": [
"text"
]
}
]
}
)
대신 ids와 fields를 쿼리 매개변수로 지정할 수도 있어요.
GET /my-index/_mtermvectors?ids=1,2&fields=text
response = client.mtermvectors(
index = "my-index",
params = { "ids": "1,2", "fields": "text" },
body = { "Insert body here" }
)
docs를 지정하는 대신 ids 배열로 문서 ID를 제공할 수도 있어요.
GET /my-index/_mtermvectors?fields=text
{
"ids": [
"1",
"2"
]
}
response = client.mtermvectors(
index = "my-index",
params = { "fields": "text" },
body = {
"ids": [
"1",
"2"
]
}
)
예제 응답 (Example response)
응답에는 두 문서에 대한 텀 벡터 정보가 들어 있어요.
{
"docs": [
{
"_index": "my-index",
"_id": "1",
"_version": 1,
"found": true,
"took": 10,
"term_vectors": {
"text": {
"field_statistics": {
"sum_doc_freq": 9,
"doc_count": 2,
"sum_ttf": 9
},
"terms": {
"a": {
"term_freq": 1,
"tokens": [
{
"position": 2,
"start_offset": 14,
"end_offset": 15
}
]
},
"engine": {
"term_freq": 1,
"tokens": [
{
"position": 4,
"start_offset": 23,
"end_offset": 29
}
]
},
"is": {
"term_freq": 1,
"tokens": [
{
"position": 1,
"start_offset": 11,
"end_offset": 13
}
]
},
"opensearch": {
"term_freq": 1,
"tokens": [
{
"position": 0,
"start_offset": 0,
"end_offset": 10
}
]
},
"search": {
"term_freq": 1,
"tokens": [
{
"position": 3,
"start_offset": 16,
"end_offset": 22
}
]
}
}
}
}
},
{
"_index": "my-index",
"_id": "2",
"_version": 1,
"found": true,
"took": 0,
"term_vectors": {
"text": {
"field_statistics": {
"sum_doc_freq": 9,
"doc_count": 2,
"sum_ttf": 9
},
"terms": {
"features": {
"term_freq": 1,
"tokens": [
{
"position": 3,
"start_offset": 29,
"end_offset": 37
}
]
},
"opensearch": {
"term_freq": 1,
"tokens": [
{
"position": 0,
"start_offset": 0,
"end_offset": 10
}
]
},
"powerful": {
"term_freq": 1,
"tokens": [
{
"position": 2,
"start_offset": 20,
"end_offset": 28
}
]
},
"provides": {
"term_freq": 1,
"tokens": [
{
"position": 1,
"start_offset": 11,
"end_offset": 19
}
]
}
}
}
}
}
]
}
응답 본문 필드 (Response body fields)
다음 표는 모든 응답 본문 필드를 나열한 것이에요.
| Field | Data type | Description | | docs | Array | A list of requested documents containing term vectors. |
docs 배열의 각 요소는 다음 필드를 포함해요.
| Field | Data type | Description | | term_vectors | Object | Contains term vector data for each field. | | term_vectors..field_statistics | Object | Contains statistics about the field. | | term_vectors..field_statistics.doc_count | Integer | The number of documents that contain at least one term in the specified field. | | term_vectors..field_statistics.sum_doc_freq | Integer | The sum of document frequencies for all terms in the field. | | term_vectors..field_statistics.sum_ttf | Integer | The sum of total term frequencies for all terms in the field. | | term_vectors..terms | Object | A map of terms in the field, in which each term includes its frequency (term_freq) and associated token information. | | term_vectors..terms..tokens | Array | An array of token objects for each term, including the token’s position in the text and its character offsets (start_offset and end_offset). |
필요한 권한 (Required permissions)
Security 플러그인을 사용한다면 적절한 권한을 확인하세요: indices:data/read/mtv and indices:data/read/mtv*