Adding documents with the API - Amazon Kendra

Adding documents with the API

The following example adds a blob of text to an index by calling BatchPutDocument. You can also add documents from an S3 bucket and call the BatchPutDocument API.

You can use the BatchPutDocument API to add documents to your index. For a list of document types supported by Amazon Kendra see Types of documents.

Files added to the index must be in a UTF-8 encoded byte stream.

For an example of creating an index using the AWS CLI and SDKs, see Creating an index. To set up the CLI and SDKs, see Setting up Amazon Kendra.

In the following examples, UTF-8 encoded text is added to the index.

import boto3 kendra = boto3.client("kendra") # Provide the index ID index_id = "index-id" # Provide the title and text title = "Information about" text = " is an online retailer." document = { "Id": "1", "Blob": text, "ContentType": "PLAIN_TEXT", "Title": title } documents = [ document ] result = kendra.batch_put_document( IndexId = index_id, Documents = documents ) print(result)
package com.amazonaws.kendra; import; import; import; import; import; import; public class AddDocumentsViaAPIExample { public static void main(String[] args) { KendraClient kendra = KendraClient.builder().build(); String indexId = "yourIndexId"; Document testDoc = Document .builder() .title("The title of your document") .id("a_doc_id") .blob(SdkBytes.fromUtf8String("your text content")) .contentType(ContentType.PLAIN_TEXT) .build(); BatchPutDocumentRequest batchPutDocumentRequest = BatchPutDocumentRequest .builder() .indexId(indexId) .documents(testDoc) .build(); BatchPutDocumentResponse result = kendra.batchPutDocument(batchPutDocumentRequest); System.out.println(String.format("BatchPutDocument Result: %s", result)); } }