2016-07-07 48 views
2

为我的单元测试我在做我的猫鼬模式的bulkindex之前使用mongoosastic截断我的模型。mongoosastic没有索​​引保存的数据

架构:

model: { 
    name: {type: String, required: true, es_indexed: true, index: 'not_analyzed'}, 
    aliases: {type: [String], es_indexed: true, index: 'not_analyzed'}, 
    birth: {type: Date, es_type: 'date', es_indexed: true, index: 
}, 

架构插件:

schema.plugin(mongoosastic, { 
    esClient, 
    index: model, 
    }); 

截断情形:

Model.esTruncate(function (err) { 

     if (err) { 
      console.error(err); 
     } 

     console.log("[ElasticSearch] Model removed") 
     Model.indexFiles(); 
    }); 

重建索引:

Model.indexFiles = function() { 
    console.log('[ElasticSearch] Start indexing ' + entityName + ' documents'); 

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

    stream.on('data', function (err, doc) { 
     count++; 
    }); 
    stream.on('close', function() { 
     console.log('[ElasticSearch] Indexed ' + count + ' ' + entityName + ' documents!'); 
    }); 
    stream.on('error', function (err) { 
     console.log('mongoosastic ERROR'); 
     console.log(err); 
    }); 
    }; 

但是我登录:

Model.on('es-indexed', function (err, res) { 
    console.log('model added to es index'); 
}); 

在我的邮路,我ES保持为空。 我不知道为什么? 此外,Model.esSearch是一个功能,它不存在库中,但它被记录在内https://github.com/mongoosastic/mongoosastic/issues/219 我认真考虑开始使用默认esClient。 你对这个图书馆有什么经验?

回答

0

这可能很难找到,但在我的情况下,它不是图书馆,这是我的ES群集健康状况是在红色,因为我没有足够的磁盘空间。 你可以尝试以下方法:

  1. 停止本地ES实例
  2. 清理一些磁盘空间
  3. ,重启ES
  4. 使用卷曲(卷曲-XDELETE 'http://localhost:9200/model/')
  5. 重新编制截断的indeces您的模型
  6. 如果仍有问题,请考虑ES中的更新记录是半实时的,因此可能会有一些延迟,并且应该在回调中进行日志记录。截断和散装索引

这为我做后运行一个短暂的延迟后您的测试...