batchPutDocument method

Future<BatchPutDocumentResponse> batchPutDocument({
  1. required List<Document> documents,
  2. required String indexId,
  3. String? roleArn,
})

Adds one or more documents to an index.

The BatchPutDocument operation enables you to ingest inline documents or a set of documents stored in an Amazon S3 bucket. Use this operation to ingest your text and unstructured text into an index, add custom attributes to the documents, and to attach an access control list to the documents added to the index.

The documents are indexed asynchronously. You can see the progress of the batch using AWS CloudWatch. Any error messages related to processing the batch are sent to your AWS CloudWatch log.

May throw ValidationException. May throw ConflictException. May throw ResourceNotFoundException. May throw ThrottlingException. May throw AccessDeniedException. May throw ServiceQuotaExceededException. May throw InternalServerException.

Parameter documents : One or more documents to add to the index.

Documents have the following file size limits.

  • 5 MB total size for inline documents
  • 50 MB total size for files from an S3 bucket
  • 5 MB extracted text for any file
For more information about file size and transaction per second quotas, see Quotas.

Parameter indexId : The identifier of the index to add the documents to. You need to create the index first using the CreateIndex operation.

Parameter roleArn : The Amazon Resource Name (ARN) of a role that is allowed to run the BatchPutDocument operation. For more information, see IAM Roles for Amazon Kendra.

Implementation

Future<BatchPutDocumentResponse> batchPutDocument({
  required List<Document> documents,
  required String indexId,
  String? roleArn,
}) async {
  ArgumentError.checkNotNull(documents, 'documents');
  ArgumentError.checkNotNull(indexId, 'indexId');
  _s.validateStringLength(
    'indexId',
    indexId,
    36,
    36,
    isRequired: true,
  );
  _s.validateStringLength(
    'roleArn',
    roleArn,
    1,
    1284,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSKendraFrontendService.BatchPutDocument'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Documents': documents,
      'IndexId': indexId,
      if (roleArn != null) 'RoleArn': roleArn,
    },
  );

  return BatchPutDocumentResponse.fromJson(jsonResponse.body);
}