gpt4 book ai didi

node.js - Elastic, mongoosastic 为什么只索引集合的一部分

转载 作者:太空宇宙 更新时间:2023-11-03 22:35:37 26 4
gpt4 key购买 nike

我在mongoosasticmongodb上使用elastic

我的问题是当我对集合进行索引时。 Mongoosastic 只索引集合的一部分(例如,我的集合有 50,000 个文档,但 mongoosastic 只索引其中的 3000 个)。

我使用此代码生成文档和索引:

var post, 
count = 0,
countes = 0;
for (i = 0; i < 50000; i++) {
post = new BlogPost(req.body)
post.save(function() {
count++;
console.log(count + "\n")
//res.redirect('/');
post.on('es-indexed', function() {
countes++;
console.log('document' + countes + ' indexed');
});
});

最佳答案

我对你为什么使用req.body有点困惑,但我认为你想做的是:

var stream = BlogPost.synchronize();
var count = 0;

stream.on('data', function(err, doc){
count++;
});

stream.on('close', function(){
console.log('indexed ' + count + ' documents!');
cb(null, 'indexed ' + count + ' documents');
});

stream.on('error', function(err){
console.log(err);
cb(err, null);
});

这将遍历您现有的 BlogPost 集合并对所有这些集合建立索引。

关于node.js - Elastic, mongoosastic 为什么只索引集合的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29792028/

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