Elasticsearch从搜索的响应正文中删除默认字段 [英] Elasticsearch remove default fields from search's response body

查看:994
本文介绍了Elasticsearch从搜索的响应正文中删除默认字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一个返回像70k文档的查询(我需要所有的,而目前使用的是扫描和滚动)



发生什么是响应是非常大(2 MB,我们alredy从6 MB减少)。我们alredy过滤了我们需要的字段,并且由于查询只是从API调用,我们减少了属性的名称。



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




  • _index(我们只在一个索引上请求) li>
  • _type(我们只需要一个类型)

  • _id(我们alredy在一个字段上有这个)

  • _score(我们没有得分)



有没有办法删除它们,所以我可以有以下结构:

 hits:[
{
_source:{
...
}
},
{
_source:{
...
}
}
pre>

]



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

解决方案

是的,你可以使用响应过滤 filter_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'


Im doing a query that returns like 70k documents (I need all of them, and Im currently using scan & scroll)

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.

What i can see is that every document in the array "hits" has the following default fields that i really dont need them:

  • _index (we only request on one index)
  • _type (we only request on one type)
  • _id (we alredy have this on a field)
  • _score (we are not scoring)

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!

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆