Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert ElasticSearch SearchResponse object to JsonObject

I want to convert the elasticsearch search result to Json Object. I havent found any proper way to convert directly.

SearchResponse response = client.prepareSearch(index).setExplain(true).execute().actionGet();

response->JSON Object.

Is there any way to convert an ElasticSearch response to a Json Object?

like image 424
Vaibhav Savala Avatar asked Mar 11 '26 22:03

Vaibhav Savala


1 Answers

In Java, you can directly convert the SearchResponse to JSONObject. Below is the handy code.

SearchResponse SR = builder.setQuery(QB).addAggregation(AB).get();

JSONObject SRJSON = new JSONObject(SR.toString());
like image 170
Hatim Stovewala Avatar answered Mar 13 '26 12:03

Hatim Stovewala