3

単体テストでは、mongoose スキーマの bulkindex を実行する前に、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