user606521
user606521

Reputation: 15434

How to filter _source before it is returned back from API?

I have many field in _source of indexed document. However I don't need all of them to be returned form search query. For now for each found document the whole _source is returned. How I can force to receive only specific fields of each _source?

Upvotes: 4

Views: 7914

Answers (1)

progrrammer
progrrammer

Reputation: 4489

So to answer your answer in general,

For version < 1

use (in search request)

{
   "fields" : ["fields you want to get"]
}

so response contains fields, not source

if version > = 1 then,

you can use

{
   "_source":[ "fields to include"]
}

source filtering can be found here .

Hope this helps.

Upvotes: 7

Related Questions