在BulkUpdate
上执行cosmos db
操作(批处理)操作时出现错误。
我还想知道如何在Java中将partition key
传递给bulk update api
。
public void function() throws Exception {
FeedOptions feedOptions = new FeedOptions();
RequestOptions options = new RequestOptions();
DocumentCollection collection = null;
collection =
documentClient.readCollection(collLink(outboundCollection),
null).getResource();
feedOptions.setEnableCrossPartitionQuery(true);
Builder bulkExecutorBuilder =
DocumentBulkExecutor.builder().from(documentClient, dbName,
outboundCollection,
collection.getPartitionKey(), 1000);
// Instantiate DocumentBulkExecutor
DocumentBulkExecutor bulkExecutor =
bulkExecutorBuilder.build();
// Integer maxConcurrencyPerPartitionRange = 20;
List<UpdateItem> updateItems = new ArrayList<UpdateItem>();
List<String> documents =
shipmentDao.queryAsJsonList(outboundCollection,
"SELECT c.id,c.outboundShipmentMessage FROM c where c.outboundShipmentMessage.messageStatusInformation.messageDeliveryStatus='Reset'");
for (String s : documents) {
Outbound outbound = objectMapper.readValue(s, Outbound.class);
options.setPartitionKey(
new PartitionKey(outbound.getOutboundShipmentMessage().getBody().getLoad().getLoadId()));
ArrayList<UpdateOperationBase> updateOperations = new ArrayList<>();
SetUpdateOperation<String> valueToBeSet = new SetUpdateOperation<String>(
"outboundShipmentMessage.messageStatusInformation.messageDeliveryStatus", "Retry");
updateOperations.add(valueToBeSet);
UpdateItem upval = new UpdateItem(outbound.getOutboundId(), "/outboundShipmentMessage/body/load/loadId",
updateOperations);
System.out.println(upval);
updateItems.add(upval);
}
System.out.println(updateItems.get(0).getPartitionKeyValue());
bulkExecutor.updateAll(updateItems, null);
}
错误消息如下:
{“错误”:[“执行函数时遇到异常。异常 =错误:{\“错误\”:[{\“严重性\”:\“错误\”,\“位置\”:{\“开始\”:103,\“结束\”:107},\“代码\“:\” SC2001 \“,\”消息\“:\”标识符 “身体”不可能 已解决。\“},{\”严重性\“:\”错误\“,\”位置\“:{\”开始\“:108,\”结束\“:112},\”代码\“:\ “ SC2001 \”,\“消息\”:\“标识符 不能“加载” 已解决。\“},{\”严重性\“:\”错误\“,\”位置\“:{\”开始\“:113,\”结束\“:119},\”代码\“:\ “ SC2001 \”,\“消息\”:\“标识符 无法解析“ loadId”。\“}]} \ r \ n堆栈跟踪:错误: {\“ errors \”:[{\“ severity \”:\“ Error \”,\“ lo”]} ActivityId: d1b379c0-b639-424f-ba72-5da5fb4cfedf,请求URI: / apps / 7eabec6a-5564-4682-acbf-478cb477a08d / services / 8b7fe258-26a1-4c94-83bb-8c41d636700d / partitions / a9329586-72e4-4704-95d6-bfa8aaa014e7 / replicas / 131934252906091782p /, RequestStats:RequestStartTime:2019-04-25T07:34:17.5277676Z, RequestEndTime:2019-04-25T07:34:17.5377703Z,地区数 尝试:1响应时间:2019-04-25T07:34:17.5377703Z,StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-eastus1-fd6.documents.azure.com:14065 / apps / 7eabec6a-5564-4682-acbf-478cb477a08d / services / 8b7fe258-26a1-4c94-83bb-8c41d636700d / partitions / a9329586- 72e4-4704-95d6-bfa8aaa014e7 / replicas / 131934252906091782p /, LSN:5807,GlobalCommittedLsn:5807,PartitionKeyRangeId:0,IsValid: True,StatusCode:400,SubStatusCode:400,RequestCharge:2.41, ItemLSN:-1,SessionToken:5807,UsingLocalLSN:False, TransportException:null,ResourceType:StoredProcedure, OperationType:ExecuteJavaScript,SDK: Microsoft.Azure.Documents.Common / 2.2.0.0,状态代码:BadRequest。 状态码为400