# Get results into array with JAVA

**URL:** <https://discuss.elastic.co/t/get-results-into-array-with-java/50520>\
**Category:** Elasticsearch\
**Created:** [May 20, 2016, 5:54am UTC](https://discuss.elastic.co/t/get-results-into-array-with-java/50520 "2016-05-20T05:54:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefansaye](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@stefansaye](https://discuss.elastic.co/u/stefansaye)\
**Post date:** [May 20, 2016, 5:54am UTC](https://discuss.elastic.co/t/get-results-into-array-with-java/50520/1 "2016-05-20T05:54:02Z")

</div>

I try to using JAVA API to query elasticsearch , but return results not include @timestamp value , and i found the result is shown "message"

SearchResponse response = client.prepareSearch("logstash-_")  
.setTypes("log")  
.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
.setQuery(QueryBuilders.queryStringQuery("value").field("name_"))// Query  
.setFrom(0).setSize(60).setExplain(true).execute()  
.actionGet();  
how to get the "\_source" and @timestamp into array and print out ? Please help me out.

java arraylist elasticsearch

---

<div class="post-metadata">

**Author:** ![NgocPham](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ngocpham/32/6242_2.png) [@NgocPham](https://discuss.elastic.co/u/NgocPham)\
**Post date:** [May 27, 2016, 4:34am UTC](https://discuss.elastic.co/t/get-results-into-array-with-java/50520/2 "2016-05-27T04:34:18Z")

</div>

try this.

```
SearchHit[] hits = response.getHits().getHits();
 for (int i = 0; i < hits.length; i++) {
 hits[i].getSourceAsString()
}

```

if you dont have any special config in index prevent auto create source. .getSourceAsString() can print it .

---

<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, 10:48pm UTC](https://discuss.elastic.co/t/get-results-into-array-with-java/50520/3 "2017-07-05T22:48:39Z")

</div>


