Retrieve all fields not working with java API

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.

What was the REST query you sent?

Hi,

here the REST Query that i've sent:

GET /my_elastic_index/_search?size=10000
{
"query" : {
"match_all" : {
}
}
}

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

Thanks xavier, that was i lookin for! Really thanks :slight_smile:

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