мы запускаем приложение javascript с панелью поиска. Контент доступен для поиска из корзины S3 AWS. JavaScript код приложения:
<html>
<head>
<script src="aws-sdk-2.604.0.js"></script>
<script>
var kendra = new AWS.Kendra({
apiVersion: '2019-02-03',
// region: '*****',
accessKeyId: '*********',
secretAccessKey: '*******************'
});
function getResults() {
var searchText = document.getElementById("searchBox").value;
var params = {
IndexId: '**************************',
/* required */
QueryText: searchText,
PageNumber: '1',
PageSize: '20'
};
kendra.query(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
document.getElementById("results").innerText = data.ResultItems[0].DocumentTitle.Text;
console.log(data); // successful response
}
});
}
</script>
</head>
<body>
<h1>This is Kendra application</h1>
<input type="text" id="searchBox" />
<button onclick="getResults()">Search</button>
<div>
<b>search results</b>
<div id="results"></div>
</div>
</body>
</html>
Вышеуказанное приложение javascript включает в себя панель поиска, которая выдает данные из корзины S3. Теперь нам нужно загрузить новый файл, используя код сервиса «BatchPutDocument», приведенный ниже. Загруженный документ (html или pdf) должен быть доступен для поиска в окне поиска приложения javascript.
Примечание: мы не должны напрямую загружать файл в корзину s3, перейдя в корзину AWS s3. Полезен ли приведенный ниже код или какой-либо другой доступный код.
var params = {
Documents: [ /* required */
{
Id: 'STRING_VALUE', /* required */
AccessControlList: [
{
Access: ALLOW | DENY, /* required */
Name: 'STRING_VALUE', /* required */
Type: USER | GROUP /* required */
},
/* more items */
],
Attributes: [
{
Key: 'STRING_VALUE', /* required */
Value: { /* required */
DateValue: new Date || 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)' || 123456789,
LongValue: 'NUMBER_VALUE',
StringListValue: [
'STRING_VALUE',
/* more items */
],
StringValue: 'STRING_VALUE'
}
},
/* more items */
],
Blob: Buffer.from('...') || 'STRING_VALUE' /* Strings will be Base-64 encoded on your behalf */,
ContentType: PDF | HTML | MS_WORD | PLAIN_TEXT | PPT,
S3Path: {
Bucket: 'STRING_VALUE', /* required */
Key: 'STRING_VALUE' /* required */
},
Title: 'STRING_VALUE'
},
/* more items */
],
IndexId: 'STRING_VALUE', /* required */
RoleArn: 'STRING_VALUE'
};
kendra.batchPutDocument(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});