弹性,猫鼬为什么只索引集合的一部分



我在mongoosastic上使用弹性

我的问题是当我对集合进行索引时。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集合并索引所有这些集合。

最新更新