gpt4 book ai didi

amazon-web-services - AWS CloudSearch 导出/下载数据

转载 作者:行者123 更新时间:2023-12-03 00:39:53 26 4
gpt4 key购买 nike

我的 AWS CloudSearch 索引中有大约 150 万个文档。这让我付出了太多的代价,我希望放弃该服务。我无法看到如何从索引下载或导出我的文档。可能吗?

最佳答案

刚刚修复了一些问题,完全归功于@Nek 的回复 https://stackoverflow.com/a/32119407/1894553

<小时/>

先决条件,node + aws-sdk 插件

$ npm install aws-sdk

导出all.js

请注意,为了使用 return: "_all_fields" 参数获取完整转储,此字段必须在架构的索引选项中启用 return 标志。

var AWS = require('aws-sdk');
var fs = require('fs');

AWS.config.update({
accessKeyId: 'xx',
secretAccessKey: 'xx',
region: 'xx',
endpoint: 'xxx'
});

var batchSize = 10000;
var compteur = 0;
var result = [];
var resultMessage = [];

var params = {query:""};
var cloudsearchdomain = new AWS.CloudSearchDomain(params);

function launchSearch(theContext) {
process.stdout.write('Launch AWS.CloudSearch ');

if (theContext==null) {
process.stdout.write('initial request ... ');
} else {
var current = (theContext.start/batchSize) +2 ;
var totalRun = (Math.ceil(theContext.found/batchSize * 10) / 10) + 1;
process.stdout.write('( ' + current + ' / ' + totalRun + ' ) ... ');
}

// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudSearchDomain.html#search-property
params = {
query:"matchall",
cursor: (theContext==null)?"initial":theContext.cursor,
size:batchSize,
queryParser: "structured",
return: "_all_fields"
};

var forCursor = new AWS.CloudSearchDomain(params);

forCursor.search(params, function(err, data) {
if (err) {
console.log("Failed with params :" );
console.log(err);
} else {
resultMessage = data;
compteur = compteur + data.hits.hit.length;
for(var i=0;i<data.hits.hit.length;i++){
result.push(data.hits.hit[i]);
};
}


process.stdout.write(resultMessage.hits.hit.length + ' hits found.');

if (resultMessage.hits.hit.length==0) {
process.stdout.write(' Done.\n\nLet\'s create thte file...\n');
writeTheFile(result);
} else {
process.stdout.write('\n');
var myContext = {};
myContext.cursor = resultMessage.hits.cursor;
myContext.start = resultMessage.hits.start;
myContext.found = resultMessage.hits.found;
myContext.retrived = resultMessage.hits.hit.length;
launchSearch(myContext);
}
});
}

function writeTheFile(myResult) {

fs.writeFile(process.argv[2], JSON.stringify(myResult), function(err) {
if(err) {
return console.log(err);
}
});
process.stdout.write("DONE : File '"+ process.argv[2] + "' generated ( " + compteur + " elements ).\n");
}



/*Check parameters*/
if (!process.argv[2]) {
//console.log(process.argv);
process.stdout.write('ERROR : the output filename is expected as argument.\n');
process.exit();
} else {
launchSearch();
}

#执行

$ node export-all.js all-data.json

关于amazon-web-services - AWS CloudSearch 导出/下载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20622228/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com