public SearchResponse search(String index, String type, JSONObject queryJson) throws IOException {
String encodedJSON = Base64.getEncoder().encodeToString(queryJson.getJSONObject("query").toJSONString().getBytes());
SearchRequest searchRequest = SearchRequest.of(s-> s.index(index)
.query(b0 -> b0.wrapper(b1 -> b1
.query(encodedJSON)))
.from(queryJson.getIntValue("from"))
.size(queryJson.getIntValue("size")));
return client.search(searchRequest, JSONObject.class);
}
Elasticsearch Java API Client queryString 语法案例
这段代码展示了如何构造一个`SearchRequest`,将JSON查询(来自`queryJson`对象)编码并应用于Elasticsearch的搜索操作,包括指定索引、类型、起始位置和返回结果数量。
2451

被折叠的 条评论
为什么被折叠?



