【问题标题】:mongoosastic not indexing data on savemongoosastic 在保存时不索引数据
【发布时间】:2016-11-09 16:50:56
【问题描述】:

对于我的单元测试,我使用 mongoosastic 截断我的模型,然后再对我的 mongoose 模式进行批量索引。

架构:

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。 您对这个图书馆有何体验?

【问题讨论】:

    标签: elasticsearch mongoosastic


    【解决方案1】:

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

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

    那是为我做的......

    【讨论】:

      猜你喜欢
      • 2019-06-30
      • 2016-03-03
      • 1970-01-01
      • 2016-06-08
      • 2015-06-29
      • 1970-01-01
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多