您可以使用Term Vectors 或 Multi Term Vectors来实现您正在寻找的内容:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html
您必须指定所需字段的ID以及字段,它将为您拥有的每个文档以及您可以轻松禁用的某些其他信息返回一组已分析的标记。
GET /exampleindex/_doc/_mtermvectors
{
"ids": [
"1","2"
],
"parameters": {
"fields": [
"*"
]
}
}
将返回以下内容:
"docs": [
{
"_index": "exampleindex",
"_type": "_doc",
"_id": "1",
"_version": 2,
"found": true,
"took": 0,
"term_vectors": {
"desc": {
"field_statistics": {
"sum_doc_freq": 5,
"doc_count": 2,
"sum_ttf": 5
},
"terms": {
"amazing": {
"term_freq": 1,
"tokens": [
{
"position": 1,
"start_offset": 3,
"end_offset": 10
}
]
},
"an": {
"term_freq": 1,
"tokens": [
{
"position": 0,
"start_offset": 0,
"end_offset": 2
}
]
}