How to search on specific fields but return the entire object matching to the fields?

Hi,

I need to search on specific fields, but respond back with entire source object matching to the fields.
I tried passing the Fields property with required field but I get response with only those fields populated with value. So I have set _source="" along with Fields but still search happening on fields other than field list.
If I use the below, then search happening on fields other than user and postdate. All I need is search only on these two fields but return the entire source object associated to the fields.
{
"fields" : ["user", "postDate"],
"_source": "
",
"query" : {
"term" : { "user" : "kimchy" }
}
}

Please help me on this.

Your search will be executed against the fields in the query. It is unrelated to the fields you request via fields or _source. That just changes what the response looks like.

So you in your query, the user field is being searched for kimchy ... postDate is not searched at all.

By default Elasticsearch will respond with the entire, original source JSON, so you don't need to do anything special there.

Thanks a lot for quick reply. Will try as per you suggestion and will keep updated this post .