将ElasticSearch SearchResponse对象转换为JsonObject [英] convert ElasticSearch SearchResponse object to JsonObject

查看:1629
本文介绍了将ElasticSearch SearchResponse对象转换为JsonObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将elasticsearch搜索结果转换为Json Object.我还没有找到直接转换的正确方法.

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.

有什么方法可以将ElasticSearch响应转换为Json对象吗?

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

推荐答案

在Java中,您可以直接将SearchResponse转换为JSONObject. 下面是方便的代码.

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());

这篇关于将ElasticSearch SearchResponse对象转换为JsonObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆