我们正在做一些操作,然后我们试图将数据插入到弹性数据库中。我的问题是,很少有记录被插入到索引中,也很少有记录丢失。我可以在我的日志文件中看到数据,而且我也没有弹性错误。由于没有错误,我也无法调试。即使没有插入,客户也会得到响应。下面是我的代码。
file.js
async function InsertModelES() {
var objn= {
PID: ID,
TID: MID,
UserID:userID,
HID: HrID,
};
await elasticClient.index({
index: 'scrn',
type: '_doc',
id: ID ,
body: objn
}, function (err, data) {
if (err) {
console.log("err ", err)
}
else {
}
})
app.js
app.post('/allrequest', async function(req, res){
let result = await file1.allrequest(data,urn);
await file1.InsertModelES()
res.send(result);
}
此问题仅在负载较高时发生。可能是什么原因?
最佳答案
这是不稳定的,正如您所说的“负载高时会发生”。如果您在索引新文档时设置 refresh=true
,它可能会解决问题。
来自 Index API :
refresh (Optional, enum) If true, Elasticsearch refreshes the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false do nothing with refreshes. Valid values: true, false, wait_for. Default: false.
关于node.js - Elasticsearch 不使用 Nodejs 插入记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66203277/