# Retrieve all fields not working with java API

**URL:** https://discuss.elastic.co/t/retrieve-all-fields-not-working-with-java-api/79067
**Category:** Elasticsearch
**Created:** [March 17, 2017, 5:12pm UTC](https://discuss.elastic.co/t/retrieve-all-fields-not-working-with-java-api/79067 "2017-03-17T17:12:56Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Pasquale\_Lodise](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Pasquale\_Lodise](https://discuss.elastic.co/u/Pasquale_Lodise)
#### Post date: [March 17, 2017, 5:12pm UTC](https://discuss.elastic.co/t/retrieve-all-fields-not-working-with-java-api/79067/1 "2017-03-17T17:12:56Z")

</div>

Hi all, i'm new to elastic. I'm using latest version ( 5.2 )  
I have a problem: if i search for all data in an index using HTTP REST, i receive the correct JSON with the desired data with all fields, like this:

```
"hits": {
    "total": 2540620,
    "max_score": 1,
    "hits": [
      {
        "_index": "my_elastic_index",
        "_type": "data",
        "_id": "AVrW0oxSraY5_uCR3s05",
        "_score": 1,
        "_source": {
          "etl_timestamp": "2015-03-03T15:10:00.000Z",
          "ggsn_mcc_mnc": "240",
          "ggsn_ip_address": "62.140.134.92",
          "data_center": null,
          "bytes_transferred_output": 42,
          "bytes_transferred_in....

```

I want to return all fields like the example above, but unfortunately i can't with my code. What's wrong with?

```
    Settings settings = Settings.builder().put("cluster.name", "my_elastic_index").build();
    TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
    SearchResponse scrollResp = client.prepareSearch("diameter_metrics").setQuery(QueryBuilders.matchAllQuery()).setTypes("data").setSize(10000).setScroll(new TimeValue(60000)).get();
    do {
	for (SearchHit hit : scrollResp.getHits().getHits()) {
	    System.out.println(hit.getFields());
	}

	scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
    } while (scrollResp.getHits().getHits().length != 0); // Zero hits
							  // mark the
							  // end of the
							  // scroll and
							  // the while
							  // loop.

```

thanks in advice.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 17, 2017, 5:35pm UTC](https://discuss.elastic.co/t/retrieve-all-fields-not-working-with-java-api/79067/2 "2017-03-17T17:35:05Z")

</div>

What was the REST query you sent?

---

<div class="post-metadata">

### Author: ![Pasquale\_Lodise](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Pasquale\_Lodise](https://discuss.elastic.co/u/Pasquale_Lodise)
#### Post date: [March 20, 2017, 8:39am UTC](https://discuss.elastic.co/t/retrieve-all-fields-not-working-with-java-api/79067/3 "2017-03-20T08:39:10Z")

</div>

Hi,

here the REST Query that i've sent:

> GET /my\_elastic\_index/\_search?size=10000  
> {  
> "query" : {  
> "match\_all" : {  
> }  
> }  
> }

---

<div class="post-metadata">

### Author: ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)
#### Post date: [March 20, 2017, 9:14am UTC](https://discuss.elastic.co/t/retrieve-all-fields-not-working-with-java-api/79067/4 "2017-03-20T09:14:55Z")

</div>

Hi,

You are looking for your document source ?

```
		Object o = hit.getSource().get(fieldName);
		Date etl_timestamp = (Date)hit.getSource().get("etl_timestamp");
		etc...

```

Else there is :

```
		hit.getIndex()
		hit.getType()
		hit.getId()
		hit.getScore()

```

Bye,  
Xavier

---

<div class="post-metadata">

### Author: ![Pasquale\_Lodise](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@Pasquale\_Lodise](https://discuss.elastic.co/u/Pasquale_Lodise)
#### Post date: [March 20, 2017, 9:52am UTC](https://discuss.elastic.co/t/retrieve-all-fields-not-working-with-java-api/79067/5 "2017-03-20T09:52:48Z")

</div>

> [@Pasquale\_Lodise](#):
>
> etl\_timestamp

Thanks xavier, that was i lookin for! Really thanks 🙂

---

<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: [April 17, 2017, 9:52am UTC](https://discuss.elastic.co/t/retrieve-all-fields-not-working-with-java-api/79067/6 "2017-04-17T09:52:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
