Elasticsearch 从搜索的响应正文中删除默认字段 [英] Elasticsearch remove default fields from search's response body
问题描述
我正在执行一个返回 70k 文档的查询(我需要所有这些文档,我目前正在使用扫描和滚动)
Im doing a query that returns like 70k documents (I need all of them, and Im currently using scan & scroll)
结果是响应非常大(2 MB,我们已经将其从 6 MB 减少了).我们已经过滤了我们需要的字段,并且由于查询仅从 API 调用,因此我们减少了属性的名称.
What happens is that the response is very large (2 MB and we alredy reduced it from 6 MB). We alredy filtered the fields we needed, and since the query is only called from an API we reduced the name of the properties.
我可以看到数组hits"中的每个文档都有以下默认字段,我真的不需要它们:
What i can see is that every document in the array "hits" has the following default fields that i really dont need them:
- _index(我们只请求一个索引)
- _type(我们只请求一种类型)
- _id(我们已经在一个领域有这个)
- _score(我们不计分)
有没有办法删除它们,这样我就可以有以下结构:
Is there a way to remove them so i can have the following structure:
"hits" : [
{
"_source": {
...
}
},
{
"_source": {
...
}
}
]
感谢阅读!我将感谢您的帮助!
Thanks for reading! I will appreciate your help!
推荐答案
是的,你可以使用 响应过滤 和 filter_path
参数,前提是您使用的是 ES 1.6 或更高版本.
Yes, you can use response filtering and the filter_path
parameter, provided you're using ES 1.6 or later.
curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source'
您甚至可以指定您想要的字段
You can even specify the just the fields you want
curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title,name'
这篇关于Elasticsearch 从搜索的响应正文中删除默认字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!