【发布时间】:2015-03-21 12:27:39
【问题描述】:
我正在尝试在 node.js 中使用 elasticsearch v 1.4.4 创建一个函数以响应错误
错误:重复 _id
就像在 mongoDB 中,当我们尝试在具有重复 _Id 的索引中插入文档时。 尽管 Elastic Search 会修改带有该 _id 的文档,但它并没有提供这样的错误。
我创建了一个函数,它首先在 elastic 上进行查询以查找具有该 id 的记录会引发错误。 但它不能实时工作。通过实时我的意思是,如果我尝试插入具有新 ID 的文档,那么它们都会插入并增加文档的版本。我尝试过 _refresh 但是不起作用。
我的功能类似于..
function checkDuplicate(index,type,id,body){
client.exists({index: index, type: type, id: id}, function (err, res) {
if (res === false) {
client.index({index: index, type: type,id:id, body: json}, function (err, response) {
resp.send(JSON.stringify(response));
})
}
else
resp.send("Error : Duplicate index doc >>>>>>>>");
});
};
【问题讨论】:
标签: node.js elasticsearch