2017-02-16 51 views
-1

我想在我的java代碼中執行以下查詢。如何在java中執行此操作?在java代碼中執行彈性搜索查詢

GET/_mapping /探索

+0

在請求直接解決方案之前,您可以添加您使用此代碼獲得的錯誤消息嗎? –

+0

最好的辦法是使用實​​現JAX-RS的庫,例如Jersey。您還可以使用Spring來使用REST服務。 – ayahuasca

回答

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()); 
} 

以上僅僅是一個爲你複製的樣本。希望能幫助到你!