# term\_vectors（词根信息）

**Term vectors**是通过分析器解析产生的信息，包括：

* 一组**terms**（词根）。
* 每个词根的位置（顺序）。
* 映射词根的首字符和尾字符与原始字符串原点的偏移量。

这些**term vectors**将被存储，一遍将他从一个特定的文档中取出。

**term\_vector** 有一下参数设置：

| no                       | 不存储**term vectors**信息。（默认值） |
| ------------------------ | --------------------------- |
| yes                      | 仅次字段中的**terms**（词根）被存储。     |
| with\_positions          | 存储词根和位置。                    |
| with\_offset             | 存储词根和字符偏移量。                 |
| with\_positions\_offsets | 存储词根、位置和字符偏移量。              |

**fast vector highlighter**需要用到 **with\_positions\_offsets**。**term vectors API**可以检索存储的任何内容。

> 警告
>
> 使用**with\_positions\_offsets** 将会是字段的索引大小增加一倍。

```
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "text": {
          "type":        "text",
          "term_vector": "with_positions_offsets"
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "text": "Quick brown fox"
}
'
curl -XGET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "text": "brown fox"
    }
  },
  "highlight": {
    "fields": {
      "text": {} #1
    }
  }
}
'
```

| 1 | 因为**term vectors**功能的使用，**text**字段将会默认使用**fast vector highlighter**。 |
| - | -------------------------------------------------------------------- |

## 解析

如上所述,词属性可以取6值,它定义是否要计算该字段的Lucene词向量(term vector).如果使用高亮,那就需要计算这个词向量.
