-1
我正在尝试编写一个简单的JAVA REST客户端,通过它我想要PUT/GET elasticsearch文档信息。 PUT工作正常,我的json数据被添加到索引中。 但问题是GET,响应代码是200,但它没有返回任何数据。ElasticSearch Rest API在JAVA中
任何人都可以请帮忙。
public static String httpGet(String resturl){
String output = null;
try {
URL url = new URL(resturl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
//System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return output;
}
我打电话的
RestClient.httpGet( “http://localhost:9200/gabsindex/employee/_search”)
你为什么要那样做?你知道在java,.net,js,python等中有多个用于elasticsearch的客户端库。 – Roman