【发布时间】:2017-09-22 13:08:53
【问题描述】:
您好,我有一个弹性搜索索引,当插入该类型的新条目时需要删除该索引。我能够创建一个 shellscript 文件并将数据插入到弹性搜索中,如下所示,
public static void main(String[] args) {
try {
// Run the process
/*Runtime.getRuntime().exec("cd src/resources");*/
Process p = Runtime.getRuntime().exec("sh src/resources/test.sh");
// Get the input stream
InputStream is = p.getInputStream();
// Read script execution results
int i;
StringBuffer sb = new StringBuffer();
while ((i = is.read()) != -1)
sb.append((char) i);
System.out.println(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
Test.sh
curl -XDELETE http://localhost:9200/pokedex
使用我的 java 程序可以插入数据但我无法删除,我尝试在命令行中运行上述命令,它工作正常。这里发生了什么?为什么它在命令行中执行而不是在我的程序中?
【问题讨论】:
-
能否添加
exec执行的shell命令的返回码?也许 shell 正在返回错误代码,但您忽略了它。
标签: java elasticsearch