これを試してください。それはHttpURLConnectionを使用してHTTP APIを介してドキュメントをインデックス付けする私のために働く。
URL obj = new URL("http://localhost:9200/index/type");
String json = "{\n" +
" \"user\" : \"kimchy\",\n" +
" \"post_date\" : \"2009-11-15T14:12:12\",\n" +
" \"message\" : \"trying out Elasticsearch\"\n" +
"}";
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
osw.write(json);
osw.flush();
osw.close();
System.out.println(con.getResponseCode() + " : " + con.getResponseMessage());
if (con != null)
con.disconnect();
HttpURLConnectionを使用した簡単な検索の実行。
URL obj = new URL("http://localhost:9200/index/type/_search");
String json = "{\n" +
" \"query\": {\n" +
" \"match_all\": {}\n" +
" }\n" +
"}";
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
osw.write(json);
osw.flush();
osw.close();
BufferedReader br = new BufferedReader(new InputStreamReader((con.getInputStream())));
System.out.println("Response : " + br.readLine());
System.out.println(con.getResponseCode() + " : " + con.getResponseMessage());
if (con != null)
con.disconnect();
コードを表示してください。 ES 5.6では、[低レベルのRESTクライアント](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-initialization)を使用することができます。 html)はApacheのHTTPクライアントのラッパーで、他の依存関係はありません。 – Val
ほとんどの場合、HTTPリクエストヘッダに 'Content-Type'ヘッダを送信していません。可能? – Val