0
私は、次のcurlコマンドを持っている:私のJavaコードは、このようなものですjavaコードでこのcurlコマンドを実行するにはどうすればいいですか?
curl -XPOST 'localhost:9200/indexname/status/_search?pretty=1&size=1000000&q=date:"2012/10/10"' -d '{"_source": {"include": [ "ID", "Name" ]}}'
:私のローカルドライブに保存されているdata.jsonファイルに、コードを実行するには
public static void main(String[] args) throws IOException{
ProcessBuilder pb = new ProcessBuilder("curl","-g","-H", "Accept:application/json", "-XPOST","localhost:9200/indexname/status/_search?pretty=1&size=10000","-d '{\"_source\": {\"include\": [ \"ID\", \"Name\" ]}}'");
pb.directory(new File("localpath"));
pb.redirectErrorStream(true);
Process p = pb.start();
InputStream is = p.getInputStream();
FileOutputStream outputStream = new FileOutputStream(
"localpath/data.json");
String line;
BufferedInputStream bis = new BufferedInputStream(is);
byte[] bytes = new byte[100];
int numberByteReaded;
while ((numberByteReaded = bis.read(bytes, 0, 100)) != -1) {
outputStream.write(bytes, 0, numberByteReaded);
Arrays.fill(bytes, (byte) 0);
}
outputStream.flush();
outputStream.close();
}
、私はこれを見ていますエラー:
{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[EsJClybMTnONMBSDBIfS9g][indexname][0]: SearchParseException[[indexname][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [ '{\"_source\": {\"include\": [ \"ID\", \"Name\" ]}}']]]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [[email protected]; line: 1, column: 3]]; }{[EsJClybMTnONMBSDBIfS9g][indexname][1]: SearchParseException[[indexname][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [ '{\"_source\": {\"include\": [ \"ID\", \"Name\" ]}}']]]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [[email protected]; line: 1, column: 3]]; }{[EsJClybMTnONMBSDBIfS9g][indexname][2]: SearchParseException[[indexname][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [ '{\"_source\": {\"include\": [ \"ID\", \"Name\" ]}}']]]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [[email protected]; line: 1, column: 3]]; }{[EsJClybMTnONMBSDBIfS9g][indexname][3]: SearchParseException[[indexname][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [ '{\"_source\": {\"include\": [ \"ID\", \"Name\" ]}}']]]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [[email protected]; line: 1, column: 3]]; }{[EsJClybMTnONMBSDBIfS9g][indexname][4]: SearchParseException[[indexname][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [ '{\"_source\": {\"include\": [ \"ID\", \"Name\" ]}}']]]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [[email protected]; line: 1, column: 3]]; }]",
"status" : 400
}
これはどうして起こっているのですか?クエリに記載されている日付のIDと名前キーの値のペアを保存します。何かアドバイス?ありがとう。
なぜ外部プロセスを使用するのではなく、このPOSTを実行するためにJavaクラスを使用しないのですか? –
私に例を教えてください。 – Sweet
私はこれが助けることができると思うhttp://stackoverflow.com/questions/3324717/sending-http-post-request-in-java –