/**
* @time: 2021/11/17 17:22
* @Param: 输入查询条件对象
* @return: 返回查询结果
* @Description: 发送滚动查询数据至kafka
*/
/*public static void sendscrollSearchData(TransportClient client, SearchRequest searchRequest) {
SearchResponse searchResponse = client.search(searchRequest).actionGet();
KafkaSink kafkaSink = new KafkaSink();
kafkaSink.open();
assert searchResponse != null;
String scrollId = sendData(searchResponse,kafkaSink);
while (searchResponse.getHits().getHits().length > 0) {
if (scrollId == null) {
break;
}
SearchScrollRequest searchScrollRequest = new SearchScrollRequest(scrollId).scroll(new Scroll(new TimeValue(60, TimeUnit.SECONDS)));
searchResponse = client.searchScroll(searchScrollRequest).actionGet();
scrollId = sendData(searchResponse,kafkaSink);
}
//清除滚屏
try {
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollId);
client.clearScroll(clearScrollRequest).actionGet();
} catch (Exception e) {
log.error("执行es滚动查询数据时发生故障", e);
}
kafkaSink.close();
}
elasticsearch滚动查询工具类 (集成版)
最新推荐文章于 2024-09-04 09:16:57 发布
该代码段展示了如何使用Elasticsearch的滚动查询(Scroll API)来分批获取搜索结果,并将这些数据发送到Kafka进行处理。首先,它执行初始搜索请求,然后在每次迭代中滚动查询,直到没有更多结果。最后,清理滚动上下文以释放资源。
摘要由CSDN通过智能技术生成