term_vector
词条向量包含有关由 分析 过程生成的词条的信息,包括
- 词条列表。
- 每个词条的位置(或顺序)。
- 将词条映射到其在原始字符串中起点的起始和结束字符偏移量。
- 载荷(如果可用)——与每个词条位置关联的用户定义的二进制数据。
可以存储这些词条向量,以便能够检索特定文档的词条向量。
term_vector
设置接受以下值:
no
- 不存储词条向量。(默认)
yes
- 只存储字段中的词条。
with_positions
- 存储词条和位置。
with_offsets
- 存储词条和字符偏移量。
with_positions_offsets
- 存储词条、位置和字符偏移量。
with_positions_payloads
- 存储词条、位置和载荷。
with_positions_offsets_payloads
- 存储词条、位置、偏移量和载荷。
快速向量高亮器需要 with_positions_offsets
。 词条向量 API 可以检索存储的任何信息。
警告
设置 with_positions_offsets
将使字段的索引大小加倍。
PUT my-index-000001
{
"mappings": {
"properties": {
"text": {
"type": "text",
"term_vector": "with_positions_offsets"
}
}
}
}
PUT my-index-000001/_doc/1
{
"text": "Quick brown fox"
}
GET my-index-000001/_search
{
"query": {
"match": {
"text": "brown fox"
}
},
"highlight": {
"fields": {
"text": {}
}
}
}
- 由于启用了词条向量,
text
字段将默认使用快速向量高亮器。