2
私の単体テスト用mongoosasticを使用して私のモデルを切り捨てる前に、私はmongooseスキーマのbulkindexを実行します。mongoosastic save on data on save
スキーマ:
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の使用を真剣に考えています。 この図書館でのあなたの経験は何ですか?