2

我在mongoosastic的mongodb上使用弹性

我的问题是当我对集合进行索引时。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');
            });
    });
4

1 回答 1

0

我对您使用的原因感到有些困惑,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集合并索引所有这些。

于 2015-12-01T15:56:05.533 回答