Hi I am using Elastic search 5.6 . As of now i cannot upgrade to higher versions. I am using Java High level rest client to fetch documents . I need to get _id in search response. I am not getting document id in search response.Please help to get the document id. I need to do bulk update of those documents later. so i need to get the document id. Also i need to get all the documents that match the result. Kindly help
SearchRequest searchRequest = new SearchRequest(DEEPDISCOVERYINDEX);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.termQuery("is_new", "true"));
searchRequest.source(searchSourceBuilder);
// Header headers=null;
/*
* try {
SearchResponse searchResponse=restHighLevelClient.search(searchRequest,
* headers);
} catch (IOException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
//List<Object> deepdiscovery_doc =new ArrayList<Object>();
try {
SearchResponse searchResponse = restHighLevelClient.search(searchRequest);
SearchHits hits =searchResponse.getHits();
SearchHit[] searchHits = hits.getHits();
for(SearchHit hit : searchHits) {
String sourceAsString =hit.getSourceAsString();
System.out.println("sourxe"+sourceAsString);
//JsonObject convertedObject = new Gson().fromJson(sourceAsString, JsonObject.class);
Gson gson=new Gson();
DeepDiscoveryDocument deepDiscoveryDoc=gson.fromJson(sourceAsString,DeepDiscoveryDocument.class);
deepDiscoveryList.add(deepDiscoveryDoc);
}
}
catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
}