我正在使用 mongoosastic 将文档索引到 ElasticSearch 中。save()、remove() 等工作正常,但是当我 update() 一个文档时,它没有在 elasticsearch 中重新索引。您能否帮助我了解如何更新 mongodb 文档,以便 mongoosastic 自动重新索引更新的文档?非常感谢。
这是代码片段
Product.update({"_id" : {$in : productIDs}}, {l2Category : req.body.newL2CategoryName}, {multi : true}, function(errUpdatingProducts){
if(errUpdatingProducts)
console.log(errUpdatingProducts);
});
在 Product Schema 中,l2Category 被索引为 String
l2Category: {
type: String,
es_indexed: true,
es_type: 'string'
},
一种方法是使用 find() 从 mongodb 服务器将数据加载到客户端,并在客户端更新每个文档,然后使用 save() 将其保存回服务器。但这似乎不是最聪明的方法。