Java读取 带密码的 elasticsearch scroll翻页
带密码的elasticsearch需要在访问时输入密码,故这里我们选择使用Curl工具的形式访问
首先我们定义一下工具类
相关的依赖可以在我之前的博客里查看
curl的工具类如下:
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class TestCurl { //输入curl命令,如果空格则以空格为分割以数据形式进行传递 public static String execCurl(String[] cmds) { ProcessBuilder process = new ProcessBuilder(cmds); Process p; try { p = process.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder builder = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { builder.append(line); builder.append(System.getProperty("line.separator")); } return