> For the complete documentation index, see [llms.txt](https://xiaoxiami.gitbook.io/elasticsearch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/mapping/323mapping-parametersff08-ying-she-can-shu-ff09/3236docvalues-ff08-wen-dang-zhi-ff09.md).

# doc\_values（文档值）

在默认情况下许多字段都是[**indexed**](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-index.html)（被索引的）,这使得它们可以被搜索.反向索引允许查询通过唯一性排序的 `term`（词根）列表来查询`term`（词根）,并且可以立即访问包含该`term`（词根）的文档.

脚本中的排序,聚合和对字段值的访问需要一种不同的数据访问模式.我们不需要先查找`term`（词根）,再寻找对应的`documents`（文档）,而是可以先查找`document`（文档）,再查找它在一个字段中的`terms`（词根）.

**Doc values**是在**document**索引时间内构建在磁盘上的数据结构,这使得上面所说的数据访问模式成为可能.它们存储&#x4E0E;**\_source** 相同的值,但是以列为主的方式存储.这使得排序和聚合效率更高.几乎所有字段类型都支持**Doc values**,除了**the notable exception of analyzed string fields.**

默认情况下,支持**doc values**的所有字段都是开启的.如果你确定不需要在字段上进行排序和聚合,活从脚本中访问字段值,则可以禁用**doc values**来节省磁盘空间.

```
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "status_code": { # 1
          "type":       "keyword"
        },
        "session_id": { # 2
          "type":       "keyword",
          "doc_values": false
        }
      }
    }
  }
}
'
```

| 1 | `status_code` 默认开启 `doc_values`         |
| - | --------------------------------------- |
| 2 | `session_id` 关闭 `doc_values`,但是仍然可以被查询. |

> 简单点理解就是可以字段值可以索引一个正排的索引,可以被排序和聚合操作
