【发布时间】:2016-08-26 22:05:07
【问题描述】:
我正在使用来自 Javascript (NodeJS) 客户端的 Elastic Search 的 Bulk API 为一堆文档编制索引。每次通话我都会发送一千个文档。该实例处理它,直到它达到 100 次调用(大约 100K 文档)。然后它会返回 Service Unavailable (503) 错误。
在进行新呼叫之前,我会等待前一个呼叫完成并额外等待一秒钟。
在搜索这个问题时,我发现了一篇讨论 Rails 修复的帖子:https://medium.com/@thetron/dealing-with-503-errors-when-testing-elasticsearch-integration-in-rails-ec7a5f828274。作者使用以下代码使错误消失:
before do
repository.create_index!
repository.client.cluster.health wait_for_status: ‘yellow’
end
基于此,我写了以下内容:
const body = [
// 1K actions/docs
];
elastic.cluster.health({
waitForStatus: 'yellow',
timeout: '60s', // I also tried using the default timeout
requestTimeout: 60000
}, function (error, response) {
if (!!error) {
console.error(error);
return;
}
elastic.bulk({
body: body
}, function (error, response) {
if (!!error) {
console.error(error);
return;
}
console.log('Success!');
});
});
不确定是否有任何区别,但该实例正在 AWS 上运行。由于文档数量众多,也许扩大实例是一种解决方案。但我想在这样做之前弄清楚如何处理这个错误。即使我必须让我的代码变慢一些。
【问题讨论】:
标签: node.js elasticsearch