How to get _id in search API in java high level rest client

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")); 
	//	Header headers=null;
		 * try { 
		 * headers); 
         } catch (IOException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		//List<Object> deepdiscovery_doc =new ArrayList<Object>(); 
		try {
			  SearchResponse searchResponse =;
			  SearchHits hits =searchResponse.getHits();
			  SearchHit[] searchHits = hits.getHits();
			  for(SearchHit hit : searchHits) {
				String sourceAsString =hit.getSourceAsString();
				//JsonObject convertedObject = new Gson().fromJson(sourceAsString, JsonObject.class);
				Gson gson=new Gson();
				DeepDiscoveryDocument deepDiscoveryDoc=gson.fromJson(sourceAsString,DeepDiscoveryDocument.class);
		catch (IOException e) { // TODO Auto-generated catch block

I'm pretty sure you can do something like:


Thanks a lot. It worked like a magic

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