AWS CloudSearch



Java SDK 연동하는 CloudSearch 관련 문서가 없는거 같다. 


1. Document Update(JSON)


- Domain

@Setter
@Getter
@ToString
public class SearchDocument {
private String id;
private String type;
private SearchItem fields;
}


@Setter
@Getter
@ToString
public class SearchItem {
String id;
private String name;
String description;
String price;
String thumbnail;
Long fileSize;
String fileExtensions;
String creatorName;
String creatorEmail;
SearchItemKind kind;
String happenedDate;
String[] categoryNames;
Long[] categoryCodes;
}



- 위 Domain 을 JSON 으로 변환한 것

각 Object 최상위에 id 와 type, fields 는 필수로 존재해야 한다.

type 값에는 add, delete 두가지가 있다.

각 field type 에 허용되는 값에 대한 설명은 아래

http://docs.aws.amazon.com/cloudsearch/latest/developerguide/configuring-index-fields.html

[
{
"id": "Marketplace_292",
"type": "add",
"fields": {
"id": "292",
"name": "Motion Graphics",
"description": "Motion Graphics description",
"price": "6.12",
"thumbnail": "http://**********/edbeb3e0-7c8c-4319-849b-863087f272c8.jpg",
"file_size": 21798,
"file_extensions": "jpg,png",
"creator_name": "hello",
"creator_email": "hello@hello.com",
"kind": "Marketplace",
"happened_date":"2016-03-26T05:12:32.545Z",
"category_names": [
"Video Motion",
"Motion Graphics",
"Overlays"
],
"category_codes": [
30,
210,
1775
]
}
}
]



Java Code


AmazonCloudSearchDomainClient domain
= new AmazonCloudSearchDomainClient(S3Manager.getCredentials());
domain.setEndpoint("********");

Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();

String str = gson.toJson(getSearchDocuments());

byte[] bytes = str.getBytes("UTF-8");

InputStream is = new ByteArrayInputStream(bytes);

UploadDocumentsRequest req = new UploadDocumentsRequest();
req.setContentType(ContentType.Applicationjson);
req.setDocuments(is);
req.setContentLength(0L + bytes.length);

UploadDocumentsResult result = domain.uploadDocuments(req);




'AWS > CloudSearch' 카테고리의 다른 글

[CloudSearch] Java SDK 사용하여 Search 하기  (0) 2016.03.29
[CloudSearch] Java SDK 로 document update  (0) 2016.03.28
YOUR COMMENT IS THE CRITICAL SUCCESS FACTOR FOR THE QUALITY OF BLOG POST