public List<UploadDocumentsResult> uploadDocuments(String domainName, List<Document> docs) { if (docs.size() == 0) { return Collections.emptyList(); } AmazonCloudSearchDomainAsyncClient domainClient = cloudSearchDomainAsyncClients.get(domainName); if (domainClient == null) { throw new IllegalArgumentException(domainName + " not known"); } List<UploadDocumentsRequest> uploadDocumentsRequests = createUploadDocumentsRequest(docs); List<UploadDocumentsResult> uploadDocumentsResults = new ArrayList<>(uploadDocumentsRequests.size()); for (UploadDocumentsRequest uploadDocumentsRequest : uploadDocumentsRequests) { UploadDocumentsResult uploadDocumentsResult = domainClient.uploadDocuments(uploadDocumentsRequest); uploadDocumentsResults.add(uploadDocumentsResult); } return uploadDocumentsResults; }
public List<Future<UploadDocumentsResult>> uploadDocumentsAsync(String domainName, List<Document> docs) { if (docs.size() == 0) { return Collections.emptyList(); } AmazonCloudSearchDomainAsyncClient domainClient = cloudSearchDomainAsyncClients.get(domainName); if (domainClient == null) { throw new IllegalArgumentException(domainName + " not known"); } List<UploadDocumentsRequest> uploadDocumentsRequests = createUploadDocumentsRequest(docs); List<Future<UploadDocumentsResult>> uploadDocumentsResults = new ArrayList<>(uploadDocumentsRequests.size()); for (UploadDocumentsRequest uploadDocumentsRequest : uploadDocumentsRequests) { Future<UploadDocumentsResult> uploadDocumentsResult = domainClient .uploadDocumentsAsync(uploadDocumentsRequest); uploadDocumentsResults.add(uploadDocumentsResult); } return uploadDocumentsResults; }
@Override public void process(List<Label> labels, String path) { LabelInsertDoc doc = new LabelInsertDoc(labels, path); Logger.Debug("Json to push: \n%s", doc.asJson()); byte[] jsonBytes = doc.asJsonBytes(); UploadDocumentsRequest pushDoc = getUploadReq(jsonBytes); UploadDocumentsResult upRes = searchClient.uploadDocuments(pushDoc); Logger.Debug("Indexed %s, %s", path, upRes.getStatus()); }
@RequestMapping(value = "/" + restResourceName , method = RequestMethod.POST, produces = "application/json") @ResponseStatus(value = HttpStatus.OK) public @ResponseBody String upsert(@RequestBody List<Matchmaker> jsonDocuments) throws Exception { UploadDocumentsResult result = null; String response = null; try { result = cloudSearchService.upsert(jsonDocuments); response = objectMapper.writeValueAsString(result); } catch (Exception e) { logger.error("", e); } return response; }
@Override public void commit() throws IOException { // nothing to do if (numDocsInBatch == 0) { return; } // close the array buffer.append(']'); LOG.info("Sending {} docs to CloudSearch", numDocsInBatch); byte[] bb = buffer.toString().getBytes(StandardCharsets.UTF_8); if (dumpBatchFilesToTemp) { try { File temp = File.createTempFile("CloudSearch_", ".json"); FileUtils.writeByteArrayToFile(temp, bb); LOG.info("Wrote batch file {}", temp.getName()); } catch (IOException e1) { LOG.error("Exception while generating batch file", e1); } finally { // reset buffer and doc counter buffer = new StringBuffer(MAX_SIZE_BATCH_BYTES).append('['); numDocsInBatch = 0; } return; } // not in debug mode try (InputStream inputStream = new ByteArrayInputStream(bb)) { UploadDocumentsRequest batch = new UploadDocumentsRequest(); batch.setContentLength((long) bb.length); batch.setContentType(ContentType.Applicationjson); batch.setDocuments(inputStream); UploadDocumentsResult result = client.uploadDocuments(batch); } catch (Exception e) { LOG.error("Exception while sending batch", e); LOG.error(buffer.toString()); } finally { // reset buffer and doc counter buffer = new StringBuffer(MAX_SIZE_BATCH_BYTES).append('['); numDocsInBatch = 0; } }
@Test public void testUpsert() throws Exception { List<Matchmaker> matchmakerList = createRandomMatchmaker(1); UploadDocumentsResult result = cloudSearchService.upsert(matchmakerList); logger.info(result.toString()); }