Search code examples
javaelasticsearchelasticsearch-java-api

Elasticsearch Java API do not return fields of hits


I have a problem with the java api for elasticsearch.

When I do a search like this:

MatchQueryBuilder query = QueryBuilders.matchQuery("_type", "booking");

SearchResponse searchResponse = client.prepareSearch().setQuery(query).execute().actionGet();

for (SearchHit hit : searchResponse.getHits()){
    Map<String, SearchHitField> fields = hit.getFields();
    System.out.println(fields.size());
}

my response never has fields, can somebody help me ? enter image description here

I'am using:

elasticsearch java api 1.4.0 elasticsearch 1.4.0

and my data looks like

{
  "_index": "bookings",
  "_type": "booking",
  "_id": "50245171",
  "_score": 1,
  "_source": {
    "field1": "value1",
    "field2": "value2",
    "field3": "value3",
    ...
  }
}

Solution

  • the fields are not responding as fields....

    with hit.getSource() i got my information