ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# doc_values(文档值) 原文链接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.3/doc-values.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/doc-values.html) 译文链接 : [http://www.apache.wiki/pages/createpage-entervariables.action?templateId=4816898&spaceKey=Elasticsearch&title=&newSpaceKey=Elasticsearch&fromPageId=9405287](http://www.apache.wiki/pages/createpage-entervariables.action?templateId=4816898&spaceKey=Elasticsearch&title=&newSpaceKey=Elasticsearch&fromPageId=9405287) 贡献者 : [程威](/display/~chengwei),[ApacheCN](/display/~apachecn),[Apache中文网](/display/~apachechina) 在默认情况下许多字段都是 [**indexed**](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-index.html)(被索引的),这使得它们可以被搜索.反向索引允许查询通过唯一性排序的 **`term`**(词根)列表来查询 **`term`**(词根),并且可以立即访问包含该 **`term`**(词根)的文档. 脚本中的排序,聚合和对字段值的访问需要一种不同的数据访问模式.我们不需要先查找 **`term`**(词根),再寻找对应的 **`documents`**(文档),而是可以先查找 **`document`**(文档),再查找它在一个字段中的 **`terms`**(词根). **Doc values** 是在 **document** 索引时间内构建在磁盘上的数据结构,这使得上面所说的数据访问模式成为可能.它们存储与 **_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`**,但是仍然可以被查询. |