源过滤和elasticsearch get API中的fields选项有什么区别?

What's the difference between source filtering and the fields option in the elasticsearch get API?

我对 elasticsearch 中 GET API 的 source filtering (i.e. using the _source_include parameter) and the fields 选项感到困惑。它们在性能方面有何不同?它们应该在什么时候使用?

更新:回复:fields

请注意,如果您刚从未来来到这里,这是 1.x 文档。

For backwards compatibility, if the fields parameter specifies fields which are not stored (store mapping set to false), it will load the _source and extract it from it. This functionality has been replaced by the source filtering parameter.

-- https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-request-fields.html#search-request-fields


AFAICT:

_source 告诉 elasticsearch 是否在响应中包含匹配文档的 source。 “源”是文档中插入的数据。

fields 告诉 elasticsearch 包含 source,但是 only 包含定义的 fields.

性能:除非您的 Elasticsearch 服务器带宽较低,否则它可以忽略不计。

我也有同样的疑问,here我找到了答案

字段限制内容被解析返回的字段

_source_filtering 限制返回的字段

另一种看待它的方式是认为字段用于优化数据传输和CPU使用,而_source_filtering 只优化数据传输

Source filtering allows us to control which parts of the original JSON document are returned for each hit[...]It's worth keeping in mind that this only saves us on bandwidth costs between the nodes participating in the search as well as the client, not CPU or Disk, as was the case when using fields.

另外:

One feature about fields that's not commonly known is the ability to select metadata-fields as well. Of particular note is its ability to select the _ttl-field, which actually returns the number of milliseconds until the document expires, not the original lifespan of the document. A very handy feature indeed.

fields 参数仅适用于 stored 字段。来自 2.3 文档:

Besides indexing the values of a field, you can also choose to store the original field value for later retrieval. Users with a Lucene background use stored fields to choose which fields they would like to be able to return in their search results. In fact the _source field is a stored field. In Elasticsearch, setting individual document fields to be stored is usually a false optimization. The whole document is already stored as the _source field. It is almost always better to just extract the fields that you need using the _source parameter.

请参阅 source filetring 了解如何限制从 _source

返回的字段