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

**URL:** https://discuss.elastic.co/t/how-to-search-on-specific-fields-but-return-the-entire-object-matching-to-the-fields/27997
**Category:** Elasticsearch
**Created:** [August 25, 2015, 9:05am UTC](https://discuss.elastic.co/t/how-to-search-on-specific-fields-but-return-the-entire-object-matching-to-the-fields/27997 "2015-08-25T09:05:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Sathish\_Dv](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@Sathish\_Dv](https://discuss.elastic.co/u/Sathish_Dv)
#### Post date: [August 25, 2015, 9:05am UTC](https://discuss.elastic.co/t/how-to-search-on-specific-fields-but-return-the-entire-object-matching-to-the-fields/27997/1 "2015-08-25T09:05:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [August 25, 2015, 1:37pm UTC](https://discuss.elastic.co/t/how-to-search-on-specific-fields-but-return-the-entire-object-matching-to-the-fields/27997/2 "2015-08-25T13:37:41Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Sathish\_Dv](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@Sathish\_Dv](https://discuss.elastic.co/u/Sathish_Dv)
#### Post date: [August 25, 2015, 5:33pm UTC](https://discuss.elastic.co/t/how-to-search-on-specific-fields-but-return-the-entire-object-matching-to-the-fields/27997/3 "2015-08-25T17:33:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:53pm UTC](https://discuss.elastic.co/t/how-to-search-on-specific-fields-but-return-the-entire-object-matching-to-the-fields/27997/4 "2017-07-05T23:53:58Z")

</div>


