Elasticsearch remove default fields from search's response body

我与影子孤独终老i 提交于 2019-12-12 07:19:47

问题


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!


回答1:


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'


来源:https://stackoverflow.com/questions/33481977/elasticsearch-remove-default-fields-from-searchs-response-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!