我正在尝试使用Azure Bulk Executor库批量插入文档/ Json。我使用了Azure文档中所述的方法:https://docs.microsoft.com/en-us/azure/cosmos-db/bulk-executor-java
以下是DocumentClient的创建:
public static DocumentClient documentClientFrom(BulkExecutionConfiguration cfg) throws DocumentClientException {
ConnectionPolicy policy = new ConnectionPolicy();
RetryOptions retryOptions = new RetryOptions();
retryOptions.setMaxRetryAttemptsOnThrottledRequests(0);
policy.setRetryOptions(retryOptions);
policy.setConnectionMode(cfg.getConnectionMode());
policy.setMaxPoolSize(cfg.getMaxConnectionPoolSize());
return new DocumentClient(cfg.getServiceEndpoint(), cfg.getMasterKey(), policy, cfg.getConsistencyLevel());
}
当我尝试如下进行批量导入时:
BulkImportResponse bulkImportResponse = bulkExecutor.importAll( documents, false, true, null );
我收到错误消息:
com.microsoft.azure.documentdb.DocumentClientException: Message: {"Errors":["Encountered exception
while executing function. Exception = Error: {\"Errors\":[\"The input content is invalid because the
required properties - 'id; ' - are missing\"]}\r\nStack trace: Error: {\"Errors\":[\"The input
content is invalid because the required properties - 'id; ' - are missing\"]}\n at createCallback
(script.js:6223:26)\n at Anonymous function (script.js:686:29)"]}
ActivityId: 3b6ca789-508d-40a2-bda1-b4e424dac88f, Request URI: /apps/6ec7164c-b528-494b-b40e-
249832f34bb1/services/221058a8-0299-4341-ad5a-0ea3d0a49cc1/partitions/ebae0619-6126-453c-b6a1-
774739a52a71/replicas/132378420031633670p/, RequestStats:
RequestStartTime: 2020-07-08T10:55:11.7899079Z, RequestEndTime: 2020-07-08T10:55:11.7999008Z, Number
of regions attempted:1
ResponseTime: 2020-07-08T10:55:11.7999008Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-
southcentralus1-fd11.documents.azure.com:14397/apps/6ec7164c-b528-494b-b40e-
249832f34bb1/services/221058a8-0299-4341-ad5a-0ea3d0a49cc1/partitions/ebae0619-6126-453c-b6a1-
774739a52a71/replicas/132378420031633670p/, LSN: 105, GlobalCommittedLsn: 105, PartitionKeyRangeId:
0, IsValid: True, StatusCode: 400, SubStatusCode: 400, RequestCharge: 4.38, ItemLSN: -1,
SessionToken: -1#105, UsingLocalLSN: False, TransportException: null, ResourceType: StoredProcedure,
OperationType: ExecuteJavaScript
, SDK: Microsoft.Azure.Documents.Common/2.11.0, StatusCode: BadRequest
at com.microsoft.azure.documentdb.internal.ErrorUtils.maybeThrowException(ErrorUtils.java:74)
at com.microsoft.azure.documentdb.internal.GatewayProxy.performPostRequest(GatewayProxy.java:284)
at com.microsoft.azure.documentdb.internal.GatewayProxy.doExecute(GatewayProxy.java:108)
at com.microsoft.azure.documentdb.internal.GatewayProxy.processMessage(GatewayProxy.java:360)
at com.microsoft.azure.documentdb.DocumentClient$5.apply(DocumentClient.java:3037)
at com.microsoft.azure.documentdb.internal.RetryUtility.executeDocumentClientRequest(RetryUtility.java:73)
at com.microsoft.azure.documentdb.DocumentClient.doCreate(DocumentClient.java:3042)
at com.microsoft.azure.documentdb.DocumentClient.executeStoredProcedure(DocumentClient.java:1571)
at com.microsoft.azure.documentdb.bulkexecutor.internal.BatchInserter$1.call(BatchInserter.java:186)
at com.microsoft.azure.documentdb.bulkexecutor.internal.BatchInserter$1.call(BatchInserter.java:158)
at com.microsoft.azure.documentdb.repackaged.com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
at com.microsoft.azure.documentdb.repackaged.com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:57)
at com.microsoft.azure.documentdb.repackaged.com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
这是我要插入的对象的json:
.........
"grocinvoiceInd": "N",
"_id": {
"transactionId": {
"$numberLong": "<xxxxxx>"
},
"txnSeqNbr": 0
},
"sourceInfo": "<xxxxxxx>"
}
显然,它似乎具有_id字段,但未插入记录。非常感谢您的帮助。
答案 0 :(得分:1)
文档中必须有一个id
字段,因为您已经使用分区键创建了一个集合,如果使用分区键创建了一个集合,则该集合中的所有文档都必须具有财产
https://docs.microsoft.com/en-us/azure/cosmos-db/partitioning-overview
也如Azure文档https://docs.microsoft.com/en-us/azure/cosmos-db/bulk-executor-java中所述,“当前,批量执行程序库仅受Azure Cosmos DB SQL API和Gremlin API帐户支持。”考虑到这一点,我们批量执行程序目前可能无法使用MongoDB存储帐户。