Elasticsearch 从搜索的响应正文中删除默认字段

Elasticsearch remove default fields from search's response body

我正在做一个 returns 像 70k 文档的查询(我需要所有这些文档,我目前正在使用扫描和滚动)

结果是响应非常大(2 MB,我们已经将其从 6 MB 减少)。我们已经过滤了所需的字段,并且由于仅从 API 调用查询,因此我们减少了属性的名称。

我可以看到数组 "hits" 中的每个文档都有以下默认字段,我真的不需要它们:

有没有办法删除它们,这样我就可以拥有以下结构:

"hits" : [
{
    "_source": {
        ...
    }
},
{
    "_source": {
        ...
    }
}

]

感谢阅读! 我会感谢你的帮助!

是的,您可以使用 response filteringfilter_path 参数,前提是您使用的是 ES 1.6 或更高版本。

curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source'

您甚至可以指定您想要的字段

curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title,name'