Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch remove default fields from search's response body

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!

like image 584
Pablo Morelli Avatar asked Dec 06 '22 19:12

Pablo Morelli


1 Answers

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'
like image 125
Val Avatar answered Jan 28 '23 09:01

Val