CloudSearchへのデータ登録・削除をJavaで実装してみました。
roleで制御するつもりなので、ローカルで動かす場合はユーザディレクトリの下の.aws/credentialsに アクセスキー・シークレットアクセスキーを設定してください。
書いてみた
public class Application
{
private final static String CLOUDSEARCH_ENDPOINT_UPLOADURL = "xxxxxxx";
public static void main(String... args)
{
// クライアントの指定
AmazonCloudSearchDomainClient cloudSearchClient = new AmazonCloudSearchDomainClient();
// エンドポイントの指定
cloudSearchClient.setEndpoint(CLOUDSEARCH_ENDPOINT_UPLOADURL);
String json = "JSON文字列";
// json文字列をbyte配列としてInputStreamを取得
byte[] bytes= json.getBytes();
ByteArrayInputStream is= new ByteArrayInputStream(bytes);
// リクエストを生成
UploadDocumentsRequest request = new UploadDocumentsRequest();
request.withContentType(ContentType.Applicationjson).withContentLength((long) bytes.length).withDocuments(is);
System.out.println("CloudSearchに対して登録・削除要求の通信開始");
UploadDocumentsResult response = cloudSearchClient.uploadDocuments(request);
System.out.println("CloudSearchに対して登録・削除要求の通信終了");
// 登録件数、削除件数表示
System.out.println(response.toString());
cloudSearchClient.shutdown();
}
}
JSON文字列の箇所はJacksonに任せました。
JSONは、 下のようなかたちにうまいこと自分でつくる必要がありそうですが、 これでデータの登録・削除要求ができます。
[
{
"id": "aaaaa",
"type": "add",
"fields": {
"name": "taro",
"lang": ["C", "Java"]
}
},
{
"id": "bbbbb",
"type": "delete",
}
]
福山
最近技術触れてないかも