awsdocs / aws-doc-sdk-examples

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.
Apache License 2.0
9.58k stars 5.63k forks source link

[Enhancement]: Add UploadDocuments example of CloudSearch service #4972

Closed tkhill-AWS closed 9 months ago

tkhill-AWS commented 1 year ago

Background story

A PHP SDK user wants an example of how to upload documents for indexing to the CloudSearch service.

Currently no CloudSearch SOS examples exist (for any SDK). Any examples for bulk uploads exist in the CloudSearch developer guide. The examples described there are for the console, CLI and direct HTTP.

What does this example accomplish?

See Background story.

Which AWS service(s)?

CloudSearch

Which AWS SDKs or tools?

Are there existing code examples to leverage?

maybe: https://docs.aws.amazon.com/cloudsearch/latest/developerguide/submitting-doc-requests.html

Do you have any reference code?

No.
tkhill-AWS commented 1 year ago

Here is the UploadDocument API details for the PHP SDK.

beqqrry-aws commented 9 months ago

It seems to me that the trouble here is not PHP or even SDK related. The call to batch upload documents is trivial, but the formatting of the JSON/XML files is not well laid out in the SDK references. https://docs.aws.amazon.com/cloudsearch/latest/developerguide/preparing-data.html#creating-document-batches has a good example of how to format it. Once that is done, the call to the SDK is only: $result = $client->uploadDocuments([ 'contentType' => 'application/json', //or 'application/xml' 'documents' => $jsonFormattedString, //or $xmlFormattedString ]);