我正在尝试检索数据表单ES查询,我对如何将每次检索到的数据转换为Java对象感到困惑。 到现在为止,我可以使用Gson获取每个JSON格式的命中,但我认为从命中转换为JSON然后转换为Java对象是没有用的。在ElasticSearch中将SearchHit转换为Java对象
我当前的代码是:
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch")
.put("path.home", "/Users/user/Apps/elasticsearch-5.4.1")
.build();
QueryBuilder qb = termQuery("price", 12);
SearchResponse response = client.prepareSearch("kal").setTypes("products")
.setSearchType(SearchType.DEFAULT)
.setQuery(qb)
.get();
SearchHit[] results = response.getHits().getHits();
for (SearchHit hit : results) {