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

标签 mongodb express elasticsearch mongoosastic

我在 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/

相关文章:

javascript - 更改 meteor 中 mongodb 集合的结构

javascript - 在 Express 路由中使用 redis

elasticsearch - 我可以在Logstash和Elasticsearch之间使用Kafka吗? (使用两个卡夫卡)

elasticsearch - ElasticSearch中的有向图建模和检索

javascript - Mongo 和 Node js 的查询返回不重复、不同

spring - 使用spring在mongodb中存储JSON模式

mongodb - mongodb db 中的解析错误,插入到具有唯一索引的集合

node.js - 如何使用 NodeJS 和 Express 将路由和模型从 app.js 中分离出来

javascript - 关于范围、node.js 和express 的问题

elasticsearch - 创建索引时如何在 Elasticsearch 模式中添加过滤器和映射?