# Get some field on searched result with JAVA

**URL:** <https://discuss.elastic.co/t/get-some-field-on-searched-result-with-java/7503>\
**Category:** Elasticsearch\
**Created:** [April 28, 2012, 12:44pm UTC](https://discuss.elastic.co/t/get-some-field-on-searched-result-with-java/7503 "2012-04-28T12:44:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmet\_DAL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmet_dal/32/2516_2.png) [@Ahmet\_DAL](https://discuss.elastic.co/u/Ahmet_DAL)\
**Post date:** [April 28, 2012, 12:44pm UTC](https://discuss.elastic.co/t/get-some-field-on-searched-result-with-java/7503/1 "2012-04-28T12:44:57Z")

</div>

Hi I'm newbie about Elastic Search. bi konuda How can i get some field  
on searched result. Assume that is the code;  
SearchResponse response = client.prepareSearch("twitter")  
.addField("user").setQuery(termQuery("user", "kimchy"))  
.execute().actionGet();  
The field is set to search query but I wanna get them all but I could  
not found the correct function for response.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 29, 2012, 5:33pm UTC](https://discuss.elastic.co/t/get-some-field-on-searched-result-with-java/7503/2 "2012-04-29T17:33:56Z")

</div>

In the SearchResponse#hits you can iterate over SearchHit, and for each  
hit, you can get fields back.

On Sat, Apr 28, 2012 at 3:44 PM, Ahmet DAL [ceahmetdal@gmail.com](mailto:ceahmetdal@gmail.com) wrote:

> Hi I'm newbie about Elastic Search. bi konuda How can i get some field  
> on searched result. Assume that is the code;  
> SearchResponse response = client.prepareSearch("twitter")
> 
> .addField("user").setQuery(termQuery("user", "kimchy"))  
> .execute().actionGet();  
> The field is set to search query but I wanna get them all but I could  
> not found the correct function for response.

---

<div class="post-metadata">

**Author:** ![ES\_User](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@ES\_User](https://discuss.elastic.co/u/ES_User)\
**Post date:** [June 28, 2013, 9:14am UTC](https://discuss.elastic.co/t/get-some-field-on-searched-result-with-java/7503/3 "2013-06-28T09:14:16Z")

</div>

Hi!

I have the same problem and want to retrieve only specific fields from the  
resultset, but i can't find it.  
My results look like this:

searchHit.field("title")) -\>  
Lorg.elasticsearch.search.internal.InternalSearchHit  
searchHit.getField() -\> same as .field

searchHit.getSourceasString shows the correct Result...

Thanks!

Am Sonntag, 29. April 2012 19:33:56 UTC+2 schrieb kimchy:

> In the SearchResponse#hits you can iterate over SearchHit, and for each  
> hit, you can get fields back.
> 
> On Sat, Apr 28, 2012 at 3:44 PM, Ahmet DAL \<[ceahm...@gmail.com](mailto:ceahm...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi I'm newbie about Elastic Search. bi konuda How can i get some field  
> > on searched result. Assume that is the code;  
> > SearchResponse response = client.prepareSearch("twitter")
> > 
> > .addField("user").setQuery(termQuery("user", "kimchy"))  
> > .execute().actionGet();  
> > The field is set to search query but I wanna get them all but I could  
> > not found the correct function for response.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:29am UTC](https://discuss.elastic.co/t/get-some-field-on-searched-result-with-java/7503/4 "2017-07-06T02:29:04Z")

</div>


