🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# store(存储) 默认情况下,字段值会被索引使他们能搜索,但他们不会被 **stored**(存储)。意思就是这个字段能查询,但不能取回他的原始值。 但这没有关系。这个字段值已经是`**[_source](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-source-field.html "_source field") **字段的一部分,他是被默认存储的。如果你只想取回一个字段或者少部分字段的值,而不是整个 **[_source](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-source-field.html "_source field")**,可以通过 **[source filtering](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-request-source-filtering.html "Source filtering")**<span style="color: rgb(68, 68, 68);"> 达到目的。</span>` 在这种情况下可以有意识的去**store**(存储)一个字段。例如,你有一个包含**title**(标题), **date**(时间)和一个很大的 **content**(内容)字段,你仅仅只想取回 **title** 和 **date** ,而不需要从整个 **`_source`**字段提取内容: | `curl -XPUT ``'localhost:9200/my_index?pretty'` `-H ``'Content-Type: application/json'` `-d'` `{` `"mappings"``: {` `"my_type"``: {` `"properties"``: {` `"title"``: {` `"type"``: ``"text"``,` `"store"``: ``true` `#1` `},` `"date"``: {` `"type"``: ``"date"``,` `"store"``: ``true` `#2` `},` `"content"``: {` `"type"``: ``"text"` `}` `}` `}` `}` `}` `'` `curl -XPUT ``'localhost:9200/my_index/my_type/1?pretty'` `-H ``'Content-Type: application/json'` `-d'` `{` `"title"``:   ``"Some short title"``,` `"date"``:    ``"2015-01-01"``,` `"content"``: ``"A very long content field..."` `}` `'` `curl -XGET ``'localhost:9200/my_index/_search?pretty'` `-H ``'Content-Type: application/json'` `-d'` `{` `"stored_fields"``: [ ``"title"``, ``"date"` `] ``#3` `}` `'` | | 1 2 | **title** 和 **date** 字段将被存储。 | | 3 | 这个请求将返回 **title** 和 **date**的值。 | 备注 **存储的字段将作为数组返回** 为了保持一致性,存储的字段将总是作为数据返回,因为没有办法知道原始字段是单个值、多值还是空数组。 如果你需要原始值,你应该从 **`_source`**字段返回。 另一种情况存储字段,是存在没有存入 **`_source`**的字段(例如 `**[copy_to](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/copy-to.html "copy_to") **字段`)。