Adding documents with the API - Amazon Kendra

Adding documents with the API

The following example adds text to an index by calling BatchPutDocument.

You can use the BatchPutDocument API to add documents in the following formats:

  • DOC

  • HTML

  • PDF

  • Plain text

  • PPT

Files added to the index must be in a UTF-8 encoded byte stream. 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)); } }