_source 被禁用时到底丢失了什么?

What exactly is lost when _source is disabled?

在 Elasticsearch 映射中禁用 _source 字段的确切后果是什么?

_source 字段本身令人惊讶的简短 documentation 仅说明

Though very handy to have around, the source field does incur storage overhead within the index. For this reason, it can be disabled.

当它被禁用时究竟是什么变得“不那么方便”没有解释。让我们跟随 link 到 get api:

By default, the get operation returns the contents of the _source field unless you have used the fields parameter or if the _source field is disabled.

同样,当 _source 被禁用时,有何不同?文档本身是否根本不可用(只剩下聚合)?系统是否回退到从各个字段重新组合文档的某些昂贵过程?

这太令人费解了。网络上许多致力于优化 Elasticsearch 性能的文档建议禁用 _source «如果您不需要它»。我怎么知道我需要它?

Elasticsearch 文档确实有一节评论了保留 _source here 所带来的好处和功能。对我影响最大的两个好处(在链接文档中列举)是:

Partial update requests will not function without the _source field.

When your mapping changes and you need to reindex your data, you can do so directly from Elasticsearch instead of having to retrieve all of your documents from another (usually slower) data store.

当然还有文档中讨论的所有其他要点,但如果您的用例需要支持增量文档级更新,那么您几乎肯定需要启用 _source

如果您有大量数据并且发现您的映射往往非常不稳定并且经常更改,您几乎肯定会希望启用 _source 以降低重建索引的成本。我目前的一个项目处于初始prototyping/development阶段,所以这个好处绝对适用。

search Elasticsearch 基于什么已经被索引。存储的数据返回。默认情况下,fields are not stored。要查看它们,需要从 _source 中重新解析它们。

因此,您可以禁用 _source,但请确保您存储了需要查看的字段。

给出了更多权衡 here