在java代码中执行弹性搜索查询

时间:2017-02-16 06:56:46

标签: java elasticsearch

我想在我的java代码中执行以下查询。如何在java中执行此操作?

  

GET / _mapping / explore

1 个答案:

答案 0 :(得分:1)

如果您有类似的内容怎么办:

if (query != null) {
     URL obj = new URL("http://localhost:9200/_mapping/explore");
     HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
     connection.setRequestMethod("GET");
     BufferedReader inputStream = new BufferedReader(new InputStreamReader(connection.getInputStream()));
     String inputLine;
     StringBuffer response = new StringBuffer();

     while ((inputLine = inputStream.readLine()) != null) {
           response.append(inputLine);
     }
     return new JSONObject(response.toString());
}

以上只是您重现的示例。希望它有所帮助!