3

对于我的单元测试,我在对我的猫鼬模式进行批量索引之前使用 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');
});

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

4

1 回答 1

0

这可能很难找到,但在我的情况下,它不是库,而是我的 ES 集群健康状态处于 RED 状态,因为我没有足够的磁盘空间。您可以尝试以下方法:

  1. 停止本地 ES 实例
  2. 清理一些磁盘空间
  3. 重启你的 ES
  4. 使用 CURL 截断索引 (curl -XDELETE ' http://localhost:9200/model/ ')
  5. 重新索引您的模型
  6. 如果仍然存在问题,请考虑到 ES 中的更新记录是半实时的,因此可能会有一些延迟,并且应该在回调中完成日志记录。在截断和批量索引后短暂延迟后运行测试

那是为我做的...

于 2016-07-07T17:21:23.550 回答