The <code>_source</code> field stores the JSON you send to Elasticsearch and you can choose to only return certain fields if needed, which is perfect for your use case. I have never heard that the stored fields will be faster for searches. The <code>_source</code> field could be bigger on disk space, but if you have to store every field there is no need to use stored fields over the <code>_source</code> field. If you do disable the source field it will mean:
You won’t be able to do partial updates
You won’t be able to re-index your data from the JSON in your Elasticsearch cluster, you’ll have to re-index from the data source (which is usually a lot slower).
默认情况下,Elasticsearch 用 JSON 字符串来表示文档主体保存在 <code>_source</code> 字段中。像其他保存的字段一样,<code>_source</code> 字段也会在写入硬盘前压缩。
这几乎始终是需要的功能,因为:
搜索结果中能得到完整的文档 —— 不需要额外去别的数据源中查询文档
如果缺少 <code>_source</code> 字段,部分 <code>更新</code> 请求不会起作用
当你的映射有变化,而且你需要重新索引数据时,你可以直接在 Elasticsearch 中操作而不需要重新从别的数据源中取回数据。
你可以从 <code>_source</code> 中通过 <code>get</code> 或 <code>search</code> 请求取回部分字段,而不是整个文档。
这样更容易排查错误,因为你可以准确的看到每个文档中包含的内容,而不是只能从一堆 ID 中猜测他们的内容。
即便如此,存储 <code>_source</code> 字段还是要占用硬盘空间的。假如上面的理由对你来说不重要,你可以用下面的映射禁用 <code>_source</code> 字段:
在搜索请求中你可以通过限定 <code>_source</code> 字段来请求指定字段:
这些字段会从 <code>_source</code> 中提取出来,而不是返回整个 <code>_source</code> 字段。
储存字段 除了索引字段的值,你也可以选择 <code>储存</code> 字段的原始值以备日后取回。使用 Lucene 做后端的用户用储存字段来选择搜索结果的返回值,事实上,<code>_source</code> 字段就是一个储存字段。 在 Elasticsearch 中,单独设置储存字段不是一个好做法。完整的文档已经被保存在 <code>_source</code> 字段中。通常最好的办法会是使用 <code>_source</code> 参数来过滤你需要的字段。
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com//p/6428321.html,如需转载请自行联系原作者