gpt4 book ai didi

mongodb - 数据没有通过 mongoosastic 从 elasticsearch 索引中删除?

转载 作者:可可西里 更新时间:2023-11-01 09:06:26 26 4
gpt4 key购买 nike

我在 MEAN 堆栈程序中设置了 mongoosastic。一切正常,除了当我从 mongodb 中删除文档时,它不会在 elasticsearch 索引中删除。因此,每次我进行包含删除项的搜索时,都会返回已删除的项,但在水合时为空。 mongoosastic 是否处理从 ES 索引中删除?我是否必须对索引刷新进行编程?

var mongoose = require('mongoose');
var mongoosastic = require("mongoosastic");
var Schema = mongoose.Schema;

var quantumSchema = new mongoose.Schema({
note: {
type: String,
require: true,
es_indexed: true
}
});

quantumSchema.plugin(mongoosastic);

var Quantum = mongoose.model('Quantum', quantumSchema);

Quantum.createMapping(function(err, mapping){
if(err){
console.log('error creating mapping (you can safely ignore this)');
console.log(err);
}else{
console.log('mapping created!');
console.log(mapping);
}
});

最佳答案

我有同样的错误。如果您查看 Documentation它指出您必须在删除文档后明确删除该文档。这就是我现在进行删除的方式。

const deleteOne = Model => async (id)=> {
const document = await Model.findByIdAndDelete(id);

if (!document) {
return new Result()
.setSuccess(false)
.setError('Unable to delete Entity with ID: ' + id + '.')
}
//this ensures the deletion from the elasticsearch index
document.remove();
return new Result()
.setSuccess(true)
.setData(document)
}

关于mongodb - 数据没有通过 mongoosastic 从 elasticsearch 索引中删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32615918/

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